Skip to content

Commit 16815be

Browse files
committed
rename files, use C functions instead of objc
1 parent 81b7ab2 commit 16815be

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

Source/MNSMiniStrings.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

Source/SSTSmallStrings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NSString *SSTStringForKey(NSString *key);

Source/MNSMiniStrings.m renamed to Source/SSTSmallStrings.m

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#import "MNSMiniStrings.h"
1+
#import "SSTSmallStrings.h"
22
#import <compression.h>
33

4-
@implementation MNSMiniStrings
5-
64
static NSDictionary <NSString *, NSString *> *sKeyToString = nil;
75

8-
+ (NSData *)_decompressedDataForFile:(NSURL *)file
6+
NSData * SSTDecompressedDataForFile(NSURL *file)
97
{
108
// The file format is: |-- 8 bytes for length of uncompressed data --|-- compressed LZFSE data --|
119
NS_VALID_UNTIL_END_OF_SCOPE NSData *compressedData = [NSData dataWithContentsOfURL:file options:NSDataReadingMappedIfSafe error:nil];
@@ -19,14 +17,14 @@ + (NSData *)_decompressedDataForFile:(NSURL *)file
1917
return [NSData dataWithBytesNoCopy:outBuffer length:actualSize freeWhenDone:YES];
2018
}
2119

22-
+ (id)_jsonForName:(NSString *)name
20+
id SSTJsonForName(NSString *name)
2321
{
2422
NSURL *compressedFile = [[NSBundle mainBundle] URLForResource:name withExtension:nil subdirectory:@"localization"];
25-
NSData *data = [self _decompressedDataForFile:compressedFile];
23+
NSData *data = SSTDecompressedDataForFile(compressedFile);
2624
return [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
2725
}
2826

29-
+ (NSDictionary <NSString *, NSString *> *)_createKeyToString
27+
NSDictionary <NSString *, NSString *> *SSTCreateKeyToString()
3028
{
3129
// Note that the preferred list does seem to at least include the development region as a fallback if there aren't
3230
// any other languages
@@ -35,9 +33,9 @@ + (id)_jsonForName:(NSString *)name
3533
return @{};
3634
}
3735
NSString *valuesPath = [NSString stringWithFormat:@"%@.values.json.lzfse", bestLocalization];
38-
NSArray <id> *values = [self _jsonForName:valuesPath];
36+
NSArray <id> *values = SSTJsonForName(valuesPath);
3937

40-
NSArray <NSString *> *keys = [self _jsonForName:@"keys.json.lzfse"];
38+
NSArray <NSString *> *keys = SSTJsonForName(@"keys.json.lzfse");
4139

4240
NSMutableDictionary <NSString *, NSString *> *keyToString = [NSMutableDictionary dictionaryWithCapacity:keys.count];
4341
NSInteger count = keys.count;
@@ -52,15 +50,13 @@ + (id)_jsonForName:(NSString *)name
5250
return keyToString; // Avoid -copy to be a bit faster
5351
}
5452

55-
+ (NSString *)stringForKey:(NSString *)key
53+
NSString *SSTStringForKey(NSString *key)
5654
{
5755
static dispatch_once_t onceToken;
5856
dispatch_once(&onceToken, ^{
59-
sKeyToString = [self _createKeyToString];
57+
sKeyToString = SSTCreateKeyToString();
6058
});
6159
// Haven't tested with CFBundleAllowMixedLocalizations set to YES, although it seems like that'd be handled by the
6260
// NSLocalizedString fallback
6361
return sKeyToString[key] ?: NSLocalizedString(key, @"");
6462
}
65-
66-
@end

0 commit comments

Comments
 (0)