Skip to content

Commit b04ab79

Browse files
committed
create
1 parent 6507492 commit b04ab79

10 files changed

Lines changed: 385 additions & 0 deletions

File tree

MergeLocalizedString.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1A46BFAE17C71BFA0059853D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A46BFAD17C71BFA0059853D /* Foundation.framework */; };
1111
1A46BFB117C71BFA0059853D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A46BFB017C71BFA0059853D /* main.m */; };
1212
1A46BFB517C71BFA0059853D /* MergeLocalizedString.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A46BFB417C71BFA0059853D /* MergeLocalizedString.1 */; };
13+
1A46BFBD17C71C0D0059853D /* FileIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A46BFBC17C71C0D0059853D /* FileIO.m */; };
1314
/* End PBXBuildFile section */
1415

1516
/* Begin PBXCopyFilesBuildPhase section */
@@ -31,6 +32,8 @@
3132
1A46BFB017C71BFA0059853D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3233
1A46BFB317C71BFA0059853D /* MergeLocalizedString-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MergeLocalizedString-Prefix.pch"; sourceTree = "<group>"; };
3334
1A46BFB417C71BFA0059853D /* MergeLocalizedString.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = MergeLocalizedString.1; sourceTree = "<group>"; };
35+
1A46BFBB17C71C0D0059853D /* FileIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileIO.h; sourceTree = "<group>"; };
36+
1A46BFBC17C71C0D0059853D /* FileIO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileIO.m; sourceTree = "<group>"; };
3437
/* End PBXFileReference section */
3538

3639
/* Begin PBXFrameworksBuildPhase section */
@@ -76,6 +79,8 @@
7679
1A46BFB017C71BFA0059853D /* main.m */,
7780
1A46BFB417C71BFA0059853D /* MergeLocalizedString.1 */,
7881
1A46BFB217C71BFA0059853D /* Supporting Files */,
82+
1A46BFBB17C71C0D0059853D /* FileIO.h */,
83+
1A46BFBC17C71C0D0059853D /* FileIO.m */,
7984
);
8085
path = MergeLocalizedString;
8186
sourceTree = "<group>";
@@ -140,6 +145,7 @@
140145
buildActionMask = 2147483647;
141146
files = (
142147
1A46BFB117C71BFA0059853D /* main.m in Sources */,
148+
1A46BFBD17C71C0D0059853D /* FileIO.m in Sources */,
143149
);
144150
runOnlyForDeploymentPostprocessing = 0;
145151
};

MergeLocalizedString.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "1.0">
5+
</Bucket>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0460"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "1A46BFA917C71BFA0059853D"
18+
BuildableName = "MergeLocalizedString"
19+
BlueprintName = "MergeLocalizedString"
20+
ReferencedContainer = "container:MergeLocalizedString.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
</Testables>
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "1A46BFA917C71BFA0059853D"
36+
BuildableName = "MergeLocalizedString"
37+
BlueprintName = "MergeLocalizedString"
38+
ReferencedContainer = "container:MergeLocalizedString.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
41+
</TestAction>
42+
<LaunchAction
43+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
44+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
45+
launchStyle = "0"
46+
useCustomWorkingDirectory = "NO"
47+
buildConfiguration = "Debug"
48+
ignoresPersistentStateOnLaunch = "NO"
49+
debugDocumentVersioning = "YES"
50+
allowLocationSimulation = "YES">
51+
<BuildableProductRunnable>
52+
<BuildableReference
53+
BuildableIdentifier = "primary"
54+
BlueprintIdentifier = "1A46BFA917C71BFA0059853D"
55+
BuildableName = "MergeLocalizedString"
56+
BlueprintName = "MergeLocalizedString"
57+
ReferencedContainer = "container:MergeLocalizedString.xcodeproj">
58+
</BuildableReference>
59+
</BuildableProductRunnable>
60+
<AdditionalOptions>
61+
</AdditionalOptions>
62+
</LaunchAction>
63+
<ProfileAction
64+
shouldUseLaunchSchemeArgsEnv = "YES"
65+
savedToolIdentifier = ""
66+
useCustomWorkingDirectory = "NO"
67+
buildConfiguration = "Release"
68+
debugDocumentVersioning = "YES">
69+
<BuildableProductRunnable>
70+
<BuildableReference
71+
BuildableIdentifier = "primary"
72+
BlueprintIdentifier = "1A46BFA917C71BFA0059853D"
73+
BuildableName = "MergeLocalizedString"
74+
BlueprintName = "MergeLocalizedString"
75+
ReferencedContainer = "container:MergeLocalizedString.xcodeproj">
76+
</BuildableReference>
77+
</BuildableProductRunnable>
78+
</ProfileAction>
79+
<AnalyzeAction
80+
buildConfiguration = "Debug">
81+
</AnalyzeAction>
82+
<ArchiveAction
83+
buildConfiguration = "Release"
84+
revealArchiveInOrganizer = "YES">
85+
</ArchiveAction>
86+
</Scheme>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>MergeLocalizedString.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>1A46BFA917C71BFA0059853D</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>

MergeLocalizedString/FileIO.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// FileIO.h
3+
// MergeLocalizedString
4+
//
5+
// Created by SmallTask on 13-8-23.
6+
// Copyright (c) 2013年 cmf. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
12+
@interface FileIO : NSObject
13+
{
14+
15+
}
16+
17+
18+
-(NSMutableDictionary *) readFile:(NSString *)filename;
19+
20+
21+
@end

MergeLocalizedString/FileIO.m

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//
2+
// FileIO.m
3+
// MergeLocalizedString
4+
//
5+
// Created by SmallTask on 13-8-23.
6+
// Copyright (c) 2013年 cmf. All rights reserved.
7+
//
8+
9+
#import "FileIO.h"
10+
11+
@implementation FileIO
12+
13+
14+
-(NSMutableDictionary *) readFile:(NSString *)filename;
15+
{
16+
NSError *error = nil;
17+
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:5000];
18+
NSString *txt = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error];
19+
if(error)
20+
NSLog(@"error:%@",[error localizedDescription]);
21+
else{
22+
// NSLog(@"%@",txt);
23+
}
24+
NSArray *txtArray = [txt componentsSeparatedByString:@"\n"];
25+
BOOL IsCommentBegin = NO;
26+
BOOL IsCommentEnd = NO;
27+
for(int i=0;i<txtArray.count;i++)
28+
{
29+
NSString *lineStr = [[txtArray objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
30+
// NSLog(@"%@",lineStr);
31+
if(lineStr.length>=2)
32+
{
33+
if(IsCommentEnd)
34+
{
35+
//恢复
36+
IsCommentBegin = NO;
37+
IsCommentEnd = NO;
38+
}
39+
40+
NSString *f2 = [lineStr substringToIndex:2];
41+
NSRange rangeE = NSMakeRange(lineStr.length-2, 2);
42+
NSString *e2 = [lineStr substringWithRange:rangeE];
43+
44+
if([f2 isEqualToString:@"/*"]){
45+
//注释开始,跳过该行
46+
IsCommentBegin = YES;
47+
if([e2 isEqualToString:@"*/"])
48+
{
49+
IsCommentBegin = NO;
50+
IsCommentEnd = NO;
51+
}
52+
continue;
53+
}
54+
55+
if([f2 isEqualToString:@"//"])
56+
{
57+
//注释,跳过该行
58+
continue;
59+
}
60+
61+
62+
if([e2 isEqualToString:@"*/"])
63+
{
64+
//注释结束,跳过该行
65+
IsCommentEnd = YES;
66+
continue;
67+
}
68+
if(IsCommentBegin)
69+
continue;
70+
71+
// NSLog(@"%@",lineStr);
72+
NSMutableArray *array = [self GetKeyValueFromLineStr:lineStr];
73+
[dict setValue:[array objectAtIndex:1] forKey:[array objectAtIndex:0]];
74+
75+
}
76+
77+
}
78+
return dict;
79+
}
80+
81+
-(NSMutableArray*)GetKeyValueFromLineStr:(NSString*)lineStr;
82+
{
83+
BOOL isKeyBegin = NO;
84+
BOOL isKeyEnd = NO;
85+
BOOL isValueBegin = NO;
86+
BOOL isValueEnd = NO;
87+
88+
NSMutableArray *outArray = [NSMutableArray arrayWithCapacity:2];
89+
90+
NSMutableString *keystr = [NSMutableString stringWithCapacity:50];
91+
NSMutableString *valuestr = [NSMutableString stringWithCapacity:50];
92+
93+
for(int i=0;i<lineStr.length;i++)
94+
{
95+
NSRange range = NSMakeRange(i,1);
96+
NSString *word = [lineStr substringWithRange:range];
97+
if(isKeyBegin==NO && [word isEqualToString:@"\""])
98+
{
99+
isKeyBegin = YES;
100+
continue;
101+
}else if(isKeyEnd==NO && [word isEqualToString:@"\\"])
102+
{
103+
//遇到转义符,后面紧接着的字符也要当成正文;
104+
[keystr appendString:word];
105+
i++;
106+
range = NSMakeRange(i,1);
107+
word = [lineStr substringWithRange:range];
108+
[keystr appendString:word];
109+
}else if(isKeyBegin && [word isEqualToString:@"\""] && isKeyEnd==NO)
110+
{
111+
isKeyEnd = YES;
112+
//keystr里的内容就是 key 的内容
113+
// NSLog(@"%@",keystr);
114+
[outArray addObject:keystr];
115+
continue;
116+
}else if(isKeyEnd==NO)
117+
{
118+
[keystr appendString:word];
119+
}else if(isKeyEnd && isValueBegin==NO && ([word isEqualToString:@"="]||[word isEqualToString:@" "]))
120+
{
121+
continue;
122+
}else if(isKeyEnd && isValueBegin==NO && [word isEqualToString:@"\""]){
123+
isValueBegin = YES;
124+
continue;
125+
}else if(isKeyEnd && isValueEnd==NO && [word isEqualToString:@"\\"]){
126+
//遇到转义符,后面紧接着的字符也要当成正文;
127+
[valuestr appendString:word];
128+
i++;
129+
range = NSMakeRange(i,1);
130+
word = [lineStr substringWithRange:range];
131+
[valuestr appendString:word];
132+
}else if(isKeyEnd && isValueBegin && isValueEnd==NO && [word isEqualToString:@"\""]){
133+
isValueEnd = YES;
134+
//valuestr里的内容就是 Value 里的内容
135+
// NSLog(@"-->%@",valuestr);
136+
[outArray addObject:valuestr];
137+
break;
138+
}else if(isValueBegin && isValueEnd==NO){
139+
[valuestr appendString:word];
140+
}
141+
142+
143+
}
144+
return outArray;
145+
}
146+
147+
@end

0 commit comments

Comments
 (0)