@@ -37,18 +37,17 @@ static OFLocale *currentLocale = nil; static OFDictionary *operatorPrecedences = nil; #ifndef OF_AMIGAOS static void -parseLocale(char *locale, of_string_encoding_t *encoding, +parseLocale(char *locale, OFStringEncoding *encoding, OFString **language, OFString **territory) { - if ((locale = of_strdup(locale)) == NULL) - return; + locale = OFStrDup(locale); @try { - const of_string_encoding_t enc = OF_STRING_ENCODING_ASCII; + OFStringEncoding enc = OFStringEncodingASCII; char *tmp; /* We don't care for extras behind the @ */ if ((tmp = strrchr(locale, '@')) != NULL) *tmp = '\0'; @@ -57,11 +56,11 @@ if ((tmp = strrchr(locale, '.')) != NULL) { *tmp++ = '\0'; @try { if (encoding != NULL) - *encoding = of_string_parse_encoding( + *encoding = OFStringEncodingParseName( [OFString stringWithCString: tmp encoding: enc]); } @catch (OFInvalidArgumentException *e) { } } @@ -77,18 +76,19 @@ if (language != NULL) *language = [OFString stringWithCString: locale encoding: enc]; } @finally { - free(locale); + OFFreeMemory(locale); } } #endif static bool -evaluateCondition(OFString *condition, OFDictionary *variables) +evaluateCondition(OFString *condition_, OFDictionary *variables) { + OFMutableString *condition = [[condition_ mutableCopy] autorelease]; OFMutableArray *tokens, *operators, *stack; /* Empty condition is the fallback that's always true */ if (condition.length == 0) return true; @@ -96,25 +96,22 @@ /* * Dirty hack to allow not needing spaces after "!" or "(" and spaces * before ")". * TODO: Replace with a proper tokenizer. */ - condition = [condition stringByReplacingOccurrencesOfString: @"!" - withString: @"! "]; - condition = [condition stringByReplacingOccurrencesOfString: @"(" - withString: @"( "]; - condition = [condition stringByReplacingOccurrencesOfString: @")" - withString: @" )"]; + [condition replaceOccurrencesOfString: @"!" withString: @"! "]; + [condition replaceOccurrencesOfString: @"(" withString: @"( "]; + [condition replaceOccurrencesOfString: @")" withString: @" )"]; /* Substitute variables and convert to RPN first */ tokens = [OFMutableArray array]; operators = [OFMutableArray array]; for (OFString *token in [condition componentsSeparatedByString: @" " - options: OF_STRING_SKIP_EMPTY]) { + options: OFStringSkipEmptyComponents]) { unsigned precedence; - of_unichar_t c; + OFUnichar c; if ([token isEqual: @"("]) { [operators addObject: @"("]; continue; } @@ -197,20 +194,20 @@ else if ([token isEqual: @"!="]) var = [OFNumber numberWithBool: ![first isEqual: second]]; else if ([token isEqual: @"<"]) var = [OFNumber numberWithBool: [first - compare: second] == OF_ORDERED_ASCENDING]; + compare: second] == OFOrderedAscending]; else if ([token isEqual: @"<="]) var = [OFNumber numberWithBool: [first - compare: second] != OF_ORDERED_DESCENDING]; + compare: second] != OFOrderedDescending]; else if ([token isEqual: @">"]) var = [OFNumber numberWithBool: [first - compare: second] == OF_ORDERED_DESCENDING]; + compare: second] == OFOrderedDescending]; else if ([token isEqual: @">="]) var = [OFNumber numberWithBool: [first - compare: second] != OF_ORDERED_ASCENDING]; + compare: second] != OFOrderedAscending]; else if ([token isEqual: @"+"]) var = [OFNumber numberWithDouble: [first doubleValue] + [second doubleValue]]; else if ([token isEqual: @"%"]) var = [OFNumber numberWithLongLong: @@ -221,11 +218,11 @@ [first boolValue] && [second boolValue]]; else if ([token isEqual: @"||"]) var = [OFNumber numberWithBool: [first boolValue] || [second boolValue]]; else - OF_ENSURE(0); + OFEnsure(0); [stack replaceObjectAtIndex: stackSize - 2 withObject: var]; [stack removeLastObject]; } else if (precedence == 1) { @@ -238,11 +235,11 @@ else if ([token isEqual: @"is_real"]) var = [OFNumber numberWithBool: ([first doubleValue] != [first longLongValue])]; else - OF_ENSURE(0); + OFEnsure(0); [stack replaceObjectAtIndex: stackSize - 1 withObject: var]; } else [stack addObject: token]; @@ -351,11 +348,11 @@ + (OFString *)territory { return currentLocale.territory; } -+ (of_string_encoding_t)encoding ++ (OFStringEncoding)encoding { return currentLocale.encoding; } + (OFString *)decimalPoint @@ -380,11 +377,11 @@ if (currentLocale != nil) @throw [OFInitializationFailedException exceptionWithClass: self.class]; - _encoding = OF_STRING_ENCODING_UTF_8; + _encoding = OFStringEncodingUTF8; _decimalPoint = @"."; _localizedStrings = [[OFMutableArray alloc] init]; if ((locale = setlocale(LC_ALL, "")) != NULL) _decimalPoint = [[OFString alloc] @@ -424,21 +421,21 @@ # elif defined(OF_AMIGAOS4) if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { # else if (0) { # endif - of_string_encoding_t ASCII = OF_STRING_ENCODING_ASCII; + OFStringEncoding ASCII = OFStringEncodingASCII; @try { - _encoding = of_string_parse_encoding( + _encoding = OFStringEncodingParseName( [OFString stringWithCString: buffer encoding: ASCII]); } @catch (OFInvalidArgumentException *e) { - _encoding = OF_STRING_ENCODING_ISO_8859_1; + _encoding = OFStringEncodingISO8859_1; } } else - _encoding = OF_STRING_ENCODING_ISO_8859_1; + _encoding = OFStringEncodingISO8859_1; /* * Get it via localeconv() instead of from the Locale struct, * to make sure we and printf etc. have the same expectations. */ @@ -457,11 +454,11 @@ @try { uint32_t territory; size_t length; territory = - OF_BSWAP32_IF_LE(locale->loc_CountryCode); + OFToBigEndian32(locale->loc_CountryCode); for (length = 0; length < 4; length++) if (((char *)&territory)[length] == 0) break; @@ -569,12 +566,11 @@ size_t last, UTF8StringLength; int state = 0; variables = [OFMutableDictionary dictionary]; while ((name = va_arg(arguments, OFConstantString *)) != nil) - [variables setObject: va_arg(arguments, id) - forKey: name]; + [variables setObject: va_arg(arguments, id) forKey: name]; for (OFDictionary *strings in _localizedStrings) { id string = [strings objectForKey: ID]; if (string == nil)