mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-03-29 09:09:07 +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/ruby
|
||||
bin/nfd
|
||||
bin/ios/deploy
|
||||
bin/ios/sim
|
||||
bin/osx/sim
|
||||
|
||||
2
Rakefile
2
Rakefile
@@ -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'])
|
||||
|
||||
15
bin/Rakefile
15
bin/Rakefile
@@ -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
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