Mercurial > projects > dstep
comparison dstep/foundation/NSNumberFormatter.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 89f3c3ef1fd2 |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module dstep.foundation.NSNumberFormatter; | 7 module dstep.foundation.NSNumberFormatter; |
8 | 8 |
9 import dstep.corefoundation.CFNumberFormatter; | 9 import dstep.corefoundation.CFNumberFormatter; |
10 import dstep.foundation.NSDecimalNumberHandler; | 10 |
11 import dstep.foundation.NSAttributedString; | |
12 import dstep.foundation.NSDecimalNumber; | |
13 import dstep.foundation.NSDictionary; | |
11 import dstep.foundation.NSError; | 14 import dstep.foundation.NSError; |
12 import dstep.foundation.NSFormatter; | 15 import dstep.foundation.NSFormatter; |
13 import dstep.foundation.NSLocale; | 16 import dstep.foundation.NSLocale; |
14 import dstep.foundation.NSMutableDictionary; | 17 import dstep.foundation.NSObjCRuntime; |
18 import dstep.foundation.NSRange; | |
19 import dstep.foundation.NSString; | |
20 import dstep.foundation.NSValue; | |
15 import dstep.objc.bridge.Bridge; | 21 import dstep.objc.bridge.Bridge; |
16 import dstep.objc.objc : id; | 22 import dstep.objc.objc; |
17 | 23 |
18 alias NSUInteger NSNumberFormatterStyle; | 24 alias NSUInteger NSNumberFormatterStyle; |
19 alias NSUInteger NSNumberFormatterBehavior; | 25 alias NSUInteger NSNumberFormatterBehavior; |
20 alias NSUInteger NSNumberFormatterPadPosition; | 26 alias NSUInteger NSNumberFormatterPadPosition; |
21 alias NSUInteger NSNumberFormatterRoundingMode; | 27 alias NSUInteger NSNumberFormatterRoundingMode; |
54 NSNumberFormatterRoundHalfEven = kCFNumberFormatterRoundHalfEven, | 60 NSNumberFormatterRoundHalfEven = kCFNumberFormatterRoundHalfEven, |
55 NSNumberFormatterRoundHalfDown = kCFNumberFormatterRoundHalfDown, | 61 NSNumberFormatterRoundHalfDown = kCFNumberFormatterRoundHalfDown, |
56 NSNumberFormatterRoundHalfUp = kCFNumberFormatterRoundHalfUp | 62 NSNumberFormatterRoundHalfUp = kCFNumberFormatterRoundHalfUp |
57 } | 63 } |
58 | 64 |
65 const TNSNumberFormatterCompatibility = ` | |
66 | |
67 bool hasThousandSeparators () | |
68 { | |
69 return invokeObjcSelf!(bool, "hasThousandSeparators"); | |
70 } | |
71 | |
72 void setHasThousandSeparators (bool flag) | |
73 { | |
74 return invokeObjcSelf!(void, "setHasThousandSeparators:", bool)(flag); | |
75 } | |
76 | |
77 NSString thousandSeparator () | |
78 { | |
79 return invokeObjcSelf!(NSString, "thousandSeparator"); | |
80 } | |
81 | |
82 void setThousandSeparator (NSString newSeparator) | |
83 { | |
84 return invokeObjcSelf!(void, "setThousandSeparator:", NSString)(newSeparator); | |
85 } | |
86 | |
87 bool localizesFormat () | |
88 { | |
89 return invokeObjcSelf!(bool, "localizesFormat"); | |
90 } | |
91 | |
92 void setLocalizesFormat (bool flag) | |
93 { | |
94 return invokeObjcSelf!(void, "setLocalizesFormat:", bool)(flag); | |
95 } | |
96 | |
97 NSString format () | |
98 { | |
99 return invokeObjcSelf!(NSString, "format"); | |
100 } | |
101 | |
102 void setFormat (NSString string) | |
103 { | |
104 return invokeObjcSelf!(void, "setFormat:", NSString)(string); | |
105 } | |
106 | |
107 NSAttributedString attributedStringForZero () | |
108 { | |
109 return invokeObjcSelf!(NSAttributedString, "attributedStringForZero"); | |
110 } | |
111 | |
112 void setAttributedStringForZero (NSAttributedString newAttributedString) | |
113 { | |
114 return invokeObjcSelf!(void, "setAttributedStringForZero:", NSAttributedString)(newAttributedString); | |
115 } | |
116 | |
117 NSAttributedString attributedStringForNil () | |
118 { | |
119 return invokeObjcSelf!(NSAttributedString, "attributedStringForNil"); | |
120 } | |
121 | |
122 void setAttributedStringForNil (NSAttributedString newAttributedString) | |
123 { | |
124 return invokeObjcSelf!(void, "setAttributedStringForNil:", NSAttributedString)(newAttributedString); | |
125 } | |
126 | |
127 NSAttributedString attributedStringForNotANumber () | |
128 { | |
129 return invokeObjcSelf!(NSAttributedString, "attributedStringForNotANumber"); | |
130 } | |
131 | |
132 void setAttributedStringForNotANumber (NSAttributedString newAttributedString) | |
133 { | |
134 return invokeObjcSelf!(void, "setAttributedStringForNotANumber:", NSAttributedString)(newAttributedString); | |
135 } | |
136 | |
137 NSDecimalNumberHandler roundingBehavior () | |
138 { | |
139 return invokeObjcSelf!(NSDecimalNumberHandler, "roundingBehavior"); | |
140 } | |
141 | |
142 void setRoundingBehavior (NSDecimalNumberHandler newRoundingBehavior) | |
143 { | |
144 return invokeObjcSelf!(void, "setRoundingBehavior:", NSDecimalNumberHandler)(newRoundingBehavior); | |
145 } | |
146 `; | |
147 | |
59 class NSNumberFormatter : NSFormatter | 148 class NSNumberFormatter : NSFormatter |
60 { | 149 { |
61 mixin ObjcWrap; | 150 mixin (ObjcWrap); |
62 mixin TNSNumberFormatterCompatibility; | 151 |
63 | |
64 Object init () | |
65 { | |
66 return invokeObjcSelf!(Object, "init"); | |
67 } | |
68 | |
69 this () | 152 this () |
70 { | 153 { |
71 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 154 super(typeof(this).alloc.init.objcObject); |
72 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); | 155 } |
73 | 156 |
74 if (result) | 157 typeof(this) init () |
75 objcObject = ret; | 158 { |
76 | 159 return invokeObjcSelf!(typeof(this), "init"); |
77 dObject = this; | 160 } |
78 } | 161 |
79 | 162 bool getObjectValue (id* obj, NSString string, NSRange* rangep, ref NSError error) |
80 bool getObjectValue (id* obj, NSString string, NSRange* rangep, NSError** error) | 163 { |
81 { | 164 id err; |
82 return invokeObjcSelf!(bool, "getObjectValue:forString:range:error:", id*, NSString, NSRange*, NSError**)(obj, string, rangep, error); | 165 |
166 if (error) | |
167 err = new objc_object; | |
168 | |
169 bool result = invokeObjcSelf!(bool, "getObjectValue:forString:range:error:", id*, NSString, NSRange*, id*)(obj, string, rangep, &err); | |
170 | |
171 if (err) | |
172 error = new NSError(err); | |
173 | |
174 return result; | |
83 } | 175 } |
84 | 176 |
85 NSString stringFromNumber (NSNumber number) | 177 NSString stringFromNumber (NSNumber number) |
86 { | 178 { |
87 return invokeObjcSelf!(NSString, "stringFromNumber:", NSNumber)(number); | 179 return invokeObjcSelf!(NSString, "stringFromNumber:", NSNumber)(number); |
132 return invokeObjcSelf!(void, "setFormatterBehavior:", uint)(behavior); | 224 return invokeObjcSelf!(void, "setFormatterBehavior:", uint)(behavior); |
133 } | 225 } |
134 | 226 |
135 static uint defaultFormatterBehavior () | 227 static uint defaultFormatterBehavior () |
136 { | 228 { |
137 return invokeObjcSelfClass!(uint, "defaultFormatterBehavior"); | 229 return invokeObjcSuperClass!(uint, "defaultFormatterBehavior"); |
138 } | 230 } |
139 | 231 |
140 static void setDefaultFormatterBehavior (uint behavior) | 232 static void setDefaultFormatterBehavior (uint behavior) |
141 { | 233 { |
142 return invokeObjcSelfClass!(void, "setDefaultFormatterBehavior:", uint)(behavior); | 234 return invokeObjcSuperClass!(void, "setDefaultFormatterBehavior:", uint)(behavior); |
143 } | 235 } |
144 | 236 |
145 NSString negativeFormat () | 237 NSString negativeFormat () |
146 { | 238 { |
147 return invokeObjcSelf!(NSString, "negativeFormat"); | 239 return invokeObjcSelf!(NSString, "negativeFormat"); |
659 | 751 |
660 void setPartialStringValidationEnabled (bool b) | 752 void setPartialStringValidationEnabled (bool b) |
661 { | 753 { |
662 return invokeObjcSelf!(void, "setPartialStringValidationEnabled:", bool)(b); | 754 return invokeObjcSelf!(void, "setPartialStringValidationEnabled:", bool)(b); |
663 } | 755 } |
756 | |
757 // TNSNumberFormatterCompatibility | |
758 bool hasThousandSeparators () | |
759 { | |
760 return invokeObjcSelf!(bool, "hasThousandSeparators"); | |
761 } | |
762 | |
763 void setHasThousandSeparators (bool flag) | |
764 { | |
765 return invokeObjcSelf!(void, "setHasThousandSeparators:", bool)(flag); | |
766 } | |
767 | |
768 NSString thousandSeparator () | |
769 { | |
770 return invokeObjcSelf!(NSString, "thousandSeparator"); | |
771 } | |
772 | |
773 void setThousandSeparator (NSString newSeparator) | |
774 { | |
775 return invokeObjcSelf!(void, "setThousandSeparator:", NSString)(newSeparator); | |
776 } | |
777 | |
778 bool localizesFormat () | |
779 { | |
780 return invokeObjcSelf!(bool, "localizesFormat"); | |
781 } | |
782 | |
783 void setLocalizesFormat (bool flag) | |
784 { | |
785 return invokeObjcSelf!(void, "setLocalizesFormat:", bool)(flag); | |
786 } | |
787 | |
788 NSString format () | |
789 { | |
790 return invokeObjcSelf!(NSString, "format"); | |
791 } | |
792 | |
793 void setFormat (NSString string) | |
794 { | |
795 return invokeObjcSelf!(void, "setFormat:", NSString)(string); | |
796 } | |
797 | |
798 NSAttributedString attributedStringForZero () | |
799 { | |
800 return invokeObjcSelf!(NSAttributedString, "attributedStringForZero"); | |
801 } | |
802 | |
803 void setAttributedStringForZero (NSAttributedString newAttributedString) | |
804 { | |
805 return invokeObjcSelf!(void, "setAttributedStringForZero:", NSAttributedString)(newAttributedString); | |
806 } | |
807 | |
808 NSAttributedString attributedStringForNil () | |
809 { | |
810 return invokeObjcSelf!(NSAttributedString, "attributedStringForNil"); | |
811 } | |
812 | |
813 void setAttributedStringForNil (NSAttributedString newAttributedString) | |
814 { | |
815 return invokeObjcSelf!(void, "setAttributedStringForNil:", NSAttributedString)(newAttributedString); | |
816 } | |
817 | |
818 NSAttributedString attributedStringForNotANumber () | |
819 { | |
820 return invokeObjcSelf!(NSAttributedString, "attributedStringForNotANumber"); | |
821 } | |
822 | |
823 void setAttributedStringForNotANumber (NSAttributedString newAttributedString) | |
824 { | |
825 return invokeObjcSelf!(void, "setAttributedStringForNotANumber:", NSAttributedString)(newAttributedString); | |
826 } | |
827 | |
828 NSDecimalNumberHandler roundingBehavior () | |
829 { | |
830 return invokeObjcSelf!(NSDecimalNumberHandler, "roundingBehavior"); | |
831 } | |
832 | |
833 void setRoundingBehavior (NSDecimalNumberHandler newRoundingBehavior) | |
834 { | |
835 return invokeObjcSelf!(void, "setRoundingBehavior:", NSDecimalNumberHandler)(newRoundingBehavior); | |
836 } | |
664 } | 837 } |
665 | |
666 template TNSNumberFormatterCompatibility () | |
667 { | |
668 bool hasThousandSeparators () | |
669 { | |
670 return invokeObjcSelf!(bool, "hasThousandSeparators"); | |
671 } | |
672 | |
673 void setHasThousandSeparators (bool flag) | |
674 { | |
675 return invokeObjcSelf!(void, "setHasThousandSeparators:", bool)(flag); | |
676 } | |
677 | |
678 NSString thousandSeparator () | |
679 { | |
680 return invokeObjcSelf!(NSString, "thousandSeparator"); | |
681 } | |
682 | |
683 void setThousandSeparator (NSString newSeparator) | |
684 { | |
685 return invokeObjcSelf!(void, "setThousandSeparator:", NSString)(newSeparator); | |
686 } | |
687 | |
688 bool localizesFormat () | |
689 { | |
690 return invokeObjcSelf!(bool, "localizesFormat"); | |
691 } | |
692 | |
693 void setLocalizesFormat (bool flag) | |
694 { | |
695 return invokeObjcSelf!(void, "setLocalizesFormat:", bool)(flag); | |
696 } | |
697 | |
698 NSString format () | |
699 { | |
700 return invokeObjcSelf!(NSString, "format"); | |
701 } | |
702 | |
703 void setFormat (NSString string) | |
704 { | |
705 return invokeObjcSelf!(void, "setFormat:", NSString)(string); | |
706 } | |
707 | |
708 NSAttributedString attributedStringForZero () | |
709 { | |
710 return invokeObjcSelf!(NSAttributedString, "attributedStringForZero"); | |
711 } | |
712 | |
713 void setAttributedStringForZero (NSAttributedString newAttributedString) | |
714 { | |
715 return invokeObjcSelf!(void, "setAttributedStringForZero:", NSAttributedString)(newAttributedString); | |
716 } | |
717 | |
718 NSAttributedString attributedStringForNil () | |
719 { | |
720 return invokeObjcSelf!(NSAttributedString, "attributedStringForNil"); | |
721 } | |
722 | |
723 void setAttributedStringForNil (NSAttributedString newAttributedString) | |
724 { | |
725 return invokeObjcSelf!(void, "setAttributedStringForNil:", NSAttributedString)(newAttributedString); | |
726 } | |
727 | |
728 NSAttributedString attributedStringForNotANumber () | |
729 { | |
730 return invokeObjcSelf!(NSAttributedString, "attributedStringForNotANumber"); | |
731 } | |
732 | |
733 void setAttributedStringForNotANumber (NSAttributedString newAttributedString) | |
734 { | |
735 return invokeObjcSelf!(void, "setAttributedStringForNotANumber:", NSAttributedString)(newAttributedString); | |
736 } | |
737 | |
738 NSDecimalNumberHandler roundingBehavior () | |
739 { | |
740 return invokeObjcSelf!(NSDecimalNumberHandler, "roundingBehavior"); | |
741 } | |
742 | |
743 void setRoundingBehavior (NSDecimalNumberHandler newRoundingBehavior) | |
744 { | |
745 return invokeObjcSelf!(void, "setRoundingBehavior:", NSDecimalNumberHandler)(newRoundingBehavior); | |
746 } | |
747 } | |
748 |