add a tool to convert UTF-8 to UTF8-MAC

This commit is contained in:
Watson
2013-09-02 14:30:58 +09:00
parent 39fe258508
commit 39a3308fcd
4 changed files with 39 additions and 4 deletions

1
.gitignore vendored
View File

@@ -5,6 +5,7 @@ s3config.yaml
bin/llc
bin/ruby
bin/nfd
bin/ios/deploy
bin/ios/sim
bin/osx/sim

View File

@@ -85,7 +85,7 @@ desc "Install"
task :install do
public_binaries = ['./bin/motion']
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'])
data = ['./NEWS']
data.concat(Dir.glob('./lib/**/*', File::FNM_DOTMATCH) - ['./lib/Rakefile'])

View File

@@ -1,7 +1,7 @@
verbose(true)
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"
@@ -33,6 +33,15 @@ task :sim do
end
end
task :clean do
%w{ruby llc ios/deploy ios/sim osx/sim}.each { |path| rm_rf(path) }
task :nfd do
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

25
bin/nfd.m Normal file
View 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("\"");
}