mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-29 05:05:37 +08:00
add a tool to convert UTF-8 to UTF8-MAC
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@ s3config.yaml
|
|||||||
|
|
||||||
bin/llc
|
bin/llc
|
||||||
bin/ruby
|
bin/ruby
|
||||||
|
bin/nfd
|
||||||
bin/ios/deploy
|
bin/ios/deploy
|
||||||
bin/ios/sim
|
bin/ios/sim
|
||||||
bin/osx/sim
|
bin/osx/sim
|
||||||
|
|||||||
2
Rakefile
2
Rakefile
@@ -85,7 +85,7 @@ desc "Install"
|
|||||||
task :install do
|
task :install do
|
||||||
public_binaries = ['./bin/motion']
|
public_binaries = ['./bin/motion']
|
||||||
binaries = public_binaries.dup.concat(['./bin/ios/deploy', './bin/ios/sim',
|
binaries = public_binaries.dup.concat(['./bin/ios/deploy', './bin/ios/sim',
|
||||||
'./bin/osx/sim', './bin/llc', './bin/ruby', './bin/ctags',
|
'./bin/osx/sim', './bin/llc', './bin/ruby', './bin/ctags', './bin/nfd',
|
||||||
'lib/yard/bin/yard', 'lib/yard/bin/yardoc', 'lib/yard/bin/yri', './lldb/lldb.py'])
|
'lib/yard/bin/yard', 'lib/yard/bin/yardoc', 'lib/yard/bin/yri', './lldb/lldb.py'])
|
||||||
data = ['./NEWS']
|
data = ['./NEWS']
|
||||||
data.concat(Dir.glob('./lib/**/*', File::FNM_DOTMATCH) - ['./lib/Rakefile'])
|
data.concat(Dir.glob('./lib/**/*', File::FNM_DOTMATCH) - ['./lib/Rakefile'])
|
||||||
|
|||||||
15
bin/Rakefile
15
bin/Rakefile
@@ -1,7 +1,7 @@
|
|||||||
verbose(true)
|
verbose(true)
|
||||||
|
|
||||||
task :default => :all
|
task :default => :all
|
||||||
task :all => [:files, :deploy, :sim]
|
task :all => [:files, :deploy, :sim, :nfd]
|
||||||
|
|
||||||
STRIP = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip"
|
STRIP = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip"
|
||||||
|
|
||||||
@@ -33,6 +33,15 @@ task :sim do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
task :clean do
|
task :nfd do
|
||||||
%w{ruby llc ios/deploy ios/sim osx/sim}.each { |path| rm_rf(path) }
|
bin = 'nfd'
|
||||||
|
if !File.exist?(bin) or File.mtime('nfd.m') > File.mtime(bin)
|
||||||
|
sh "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -mmacosx-version-min=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -I./src -std=c99 -Wall -O3 nfd.m -o \"#{bin}\" -framework Foundation -I."
|
||||||
|
sh "#{STRIP} -x \"#{bin}\""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
task :clean do
|
||||||
|
%w{ruby llc ios/deploy ios/sim osx/sim ndf}.each { |path| rm_rf(path) }
|
||||||
end
|
end
|
||||||
|
|||||||
25
bin/nfd.m
Normal file
25
bin/nfd.m
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Convert UTF-8 from Normalization Form C (NFC) to Normalization Form D (NFD)
|
||||||
|
// This tool outputs the escaped Ruby string.
|
||||||
|
// ex) ./nfd "a" #=> "\x61"
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
[[NSAutoreleasePool alloc] init];
|
||||||
|
if (argc <= 0) {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *cstr = argv[1];
|
||||||
|
NSString *str = [[[NSString alloc] initWithCString:cstr encoding:NSUTF8StringEncoding] autorelease];
|
||||||
|
NSString *str_nfd = [str decomposedStringWithCanonicalMapping];
|
||||||
|
|
||||||
|
// output the string
|
||||||
|
const char *string = [str_nfd UTF8String];
|
||||||
|
const long len = strlen(string);
|
||||||
|
printf("\"");
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
printf("\\x%X", (unsigned char)string[i]);
|
||||||
|
}
|
||||||
|
printf("\"");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user