etc: update etc/unicode.py for the changes made to std::unicode.

This commit is contained in:
Huon Wilson
2013-06-29 11:19:14 +10:00
parent 9e83b2fe55
commit 562dea1820
2 changed files with 25 additions and 12 deletions

View File

@@ -122,14 +122,14 @@ def ch_prefix(ix):
def emit_bsearch_range_table(f):
f.write("""
pure fn bsearch_range_table(c: char, r: &[(char,char)]) -> bool {
use cmp::{EQ, LT, GT};
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use cmp::{Equal, Less, Greater};
use vec::bsearch;
use option::None;
(do bsearch(r) |&(lo,hi)| {
if lo <= c && c <= hi { EQ }
else if hi < c { LT }
else { GT }
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
}) != None
}\n\n
""");
@@ -140,7 +140,7 @@ def emit_property_module(f, mod, tbl):
keys.sort()
emit_bsearch_range_table(f);
for cat in keys:
f.write(" const %s_table : &[(char,char)] = &[\n" % cat)
f.write(" static %s_table : &'static [(char,char)] = &[\n" % cat)
ix = 0
for pair in tbl[cat]:
f.write(ch_prefix(ix))
@@ -148,7 +148,7 @@ def emit_property_module(f, mod, tbl):
ix += 1
f.write("\n ];\n\n")
f.write(" pub pure fn %s(c: char) -> bool {\n" % cat)
f.write(" pub fn %s(c: char) -> bool {\n" % cat)
f.write(" bsearch_range_table(c, %s_table)\n" % cat)
f.write(" }\n\n")
f.write("}\n")
@@ -159,7 +159,7 @@ def emit_property_module_old(f, mod, tbl):
keys = tbl.keys()
keys.sort()
for cat in keys:
f.write(" pure fn %s(c: char) -> bool {\n" % cat)
f.write(" fn %s(c: char) -> bool {\n" % cat)
f.write(" ret alt c {\n")
prefix = ' '
for pair in tbl[cat]:
@@ -236,8 +236,22 @@ rf = open(r, "w")
(canon_decomp, compat_decomp, gencats) = load_unicode_data("UnicodeData.txt")
# Explain that the source code was generated by this script.
rf.write('// The following code was generated by "src/etc/unicode.py"\n\n')
# Preamble
rf.write('''// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// The following code was generated by "src/etc/unicode.py"
#[allow(missing_doc)];
''')
emit_property_module(rf, "general_category", gencats)