Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Move Cocotron into subfolder.

* Add more string tests.


git-svn-id: https://opencflite.svn.sourceforge.net/svnroot/opencflite@114 949b7c4e-b822-e185-8c53-f993a654f32e
  • Loading branch information...
commit e523e390e8ea9188839322a87396514eb09a177b 1 parent f2f9908
bfulgham authored
View
2  CFString.c
@@ -2702,7 +2702,7 @@ Boolean CFStringFindWithOptionsAndLocale(CFStringRef string, CFStringRef stringT
if (compareOptions & kCFCompareLocalized) {
CFLocaleRef currentLocale = CFLocaleCopyCurrent();
langCode = (const uint8_t *)_CFStrGetLanguageIdentifierForLocale(currentLocale);
- CFRelease(currentLocale);
+ CFRelease(currentLocale);
}
} else {
langCode = (const uint8_t *)_CFStrGetLanguageIdentifierForLocale(locale);
View
0  Cocotron.c → Cocotron/Cocotron.c
File renamed without changes
View
0  CoreFoundation.xcodeproj/project.pbxproj → Cocotron/CoreFoundation.xcodeproj/project.pbxproj
File renamed without changes
View
158 examples/StringExample/StringExample.c
@@ -37,10 +37,11 @@
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <CoreFoundation/CoreFoundation.h>
#include <stdio.h>
#include <stdlib.h>
+#include <CoreFoundation/CoreFoundation.h>
+
// This function will print the provided arguments (printf style varargs) out to the console.
// Note that the CFString formatting function accepts "%@" as a way to display CF types.
@@ -374,28 +375,151 @@ void stringManipulation(void) {
CFRelease(strChange);
}
+Boolean equalValues(CFStringRef number, CFNumberRef expected, CFNumberFormatterStyle style, CFNumberFormatterOptionFlags option)
+{
+ CFLocaleRef curLocale = CFLocaleCopyCurrent();
+ CFNumberFormatterRef fmt;
+ CFNumberRef val;
+
+ show(CFSTR("Make a Number from : %@"), number);
+
+ fmt = CFNumberFormatterCreate (0, curLocale, style);
+ val = CFNumberFormatterCreateNumberFromString(0, fmt, number, 0, option);
+
+ show(CFSTR("val=%@, should be=%@\n"), val, expected);
+
+ if (!val)
+ return false;
+
+ return (0 == CFNumberCompare(val, expected, 0));
+}
+
void stringHandling(void) {
CFStringRef number;
- CFNumberRef val, compare;
- CFNumberFormatterRef fmt;
- CFLocaleRef curLocale;
- int theValue = 89;
+ int theValue = 80;
+ double theOtherValue = 123.26;
+ CFNumberRef expected = CFNumberCreate(0, kCFNumberIntType, &theValue);
show(CFSTR("------------------Number Magic---------------"));
+ show(CFSTR("1. Integer Parsing"));
+ show(CFSTR(" (a) Decimal Style"));
+
+ number = CFStringCreateWithCString(NULL, "80.0", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterDecimalStyle, kCFNumberFormatterParseIntegersOnly))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (b) Currency Style"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "$80.00", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterCurrencyStyle, kCFNumberFormatterParseIntegersOnly))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (c) Percent Style (does not work for integers)"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "80%", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterPercentStyle, kCFNumberFormatterParseIntegersOnly))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (d) Scientific Notation Style (does not work for integers)"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "8.0E1", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterScientificStyle, kCFNumberFormatterParseIntegersOnly))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (e) Spell-Out Style"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "eighty", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterSpellOutStyle, kCFNumberFormatterParseIntegersOnly))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (f) No Style (decimal)"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "80.0", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterNoStyle, kCFNumberFormatterParseIntegersOnly))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (g) No Style (spell out) (is not expected to work)"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "eighty", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterNoStyle, kCFNumberFormatterParseIntegersOnly))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR("2. Decimal Parsing"));
+ show(CFSTR(" (a) Decimal Style"));
- number = CFStringCreateWithCString(NULL, "eighty", kCFStringEncodingASCII);
- compare = CFNumberCreate(0, kCFNumberIntType, &theValue);
-
- show(CFSTR("Make a Number from : %@"), number);
-
- curLocale = CFLocaleCopyCurrent ();
- fmt = CFNumberFormatterCreate (0, curLocale, kCFNumberFormatterSpellOutStyle);
- val = CFNumberFormatterCreateNumberFromString(0, fmt, number, 0, kCFNumberFormatterParseIntegersOnly);
-
- show(CFSTR("val=%@, compare=%@\n"), val, compare);
-
- CFRelease(curLocale);
+ CFRelease(expected);
+ expected = CFNumberCreate(0, kCFNumberDoubleType, &theOtherValue);
+
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "123.26", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterDecimalStyle, 0))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (b) Currency Style"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "$123.26", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterCurrencyStyle, 0))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (c) Percent Style"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "123.26%", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterPercentStyle, 0))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (d) Scientific Notation Style"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "1.2326e2", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterScientificStyle, 0))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (e) Spell-Out Style"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "one hundred twenty-three point two six", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterSpellOutStyle, 0))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (f) No Style (decimal)"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "123.26", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterNoStyle, 0))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
+ show(CFSTR(" (g) No Style (spell-out) (not expected to work)"));
+ CFRelease(number);
+ number = CFStringCreateWithCString(NULL, "one hundred twenty three point two six", kCFStringEncodingASCII);
+ if (equalValues(number, expected, kCFNumberFormatterNoStyle, 0))
+ show(CFSTR("correct."));
+ else
+ show(CFSTR("WRONG!!!"));
+
CFRelease(number);
}
View
6 macosx/CFLite.xcodeproj/project.pbxproj
@@ -60,7 +60,6 @@
84129F9F0F3A4C2600A64427 /* CFXMLParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 848B55CE0ECFAF07003D696F /* CFXMLParser.h */; };
84129FA00F3A4C2600A64427 /* CoreFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 848B55CF0ECFAF07003D696F /* CoreFoundation.h */; };
841BE8470F395D91001F2A66 /* StringExample.c in Sources */ = {isa = PBXBuildFile; fileRef = 841BE83B0F395D3E001F2A66 /* StringExample.c */; };
- 841BE8490F395DA9001F2A66 /* CFLite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8448EF670ED2796500716715 /* CFLite.framework */; };
841BE9230F395FB4001F2A66 /* AllocatorExample.c in Sources */ = {isa = PBXBuildFile; fileRef = 841BE91A0F395F65001F2A66 /* AllocatorExample.c */; };
841BE9250F395FBE001F2A66 /* CFLite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8448EF670ED2796500716715 /* CFLite.framework */; };
8448EF6C0ED2798800716715 /* CFApplicationPreferences.c in Sources */ = {isa = PBXBuildFile; fileRef = 848B55480ECFAE4D003D696F /* CFApplicationPreferences.c */; };
@@ -142,6 +141,7 @@
84DA17230EDDF47100B6A2E6 /* CFLite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8448EF670ED2796500716715 /* CFLite.framework */; };
84DA17270EDDF47E00B6A2E6 /* date_test.c in Sources */ = {isa = PBXBuildFile; fileRef = 84DA170D0EDDEEEE00B6A2E6 /* date_test.c */; };
84DE4E550ED287D40023DFE2 /* CFLite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8448EF670ED2796500716715 /* CFLite.framework */; };
+ 84F19F470F50FAC70092A274 /* CFLite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8448EF670ED2796500716715 /* CFLite.framework */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -310,6 +310,7 @@
84CD60DB0F4A03310049B4EC /* SimpleWebServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SimpleWebServer; sourceTree = BUILT_PRODUCTS_DIR; };
84DA170D0EDDEEEE00B6A2E6 /* date_test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = date_test.c; path = ../tests/date_test.c; sourceTree = SOURCE_ROOT; };
84DA171C0EDDF44500B6A2E6 /* Test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Test; sourceTree = BUILT_PRODUCTS_DIR; };
+ 84F19F070F50F9CE0092A274 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -317,7 +318,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- 841BE8490F395DA9001F2A66 /* CFLite.framework in Frameworks */,
+ 84F19F470F50FAC70092A274 /* CFLite.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -409,6 +410,7 @@
C6A0FF2B0290797F04C91782 /* Documentation */,
1AB674ADFE9D54B511CA2CBB /* Products */,
845EDB360ED3374D0033E001 /* Info.plist */,
+ 84F19F070F50F9CE0092A274 /* CoreFoundation.framework */,
);
comments = "This XCode project attempts to replicate the steps performed in the BuildCFLite shell script. For real production use, you should always use the script as it is maintained by the Apple team, and always does the right thing. This XCode project is mainly for exploration and debugging purposes, and is sometimes out of sync with the BuildCFLite script.\n\nIf something is not working right, be sure to compare the settings in BuildCFLite and this project!";
name = CFLite;
Please sign in to comment.
Something went wrong with that request. Please try again.