         ] each-element mapping ranges 
     ] ;
 
-! Algorithms from:
-! http://www-128.ibm.com/developerworks/library/u-china.html
-
-: linear ( bytes -- num )
-    ! This hard-codes bMin and bMax
-    reverse first4
-    10 * + 126 * + 10 * + ;
-
 : unlinear ( num -- bytes )
     B{ HEX: 81 HEX: 30 HEX: 81 HEX: 30 } linear -
-    10 /mod swap [ HEX: 30 + ] dip
-    126 /mod swap [ HEX: 81 + ] dip
-    10 /mod swap [ HEX: 30 + ] dip
+    10 /mod HEX: 30 + swap
+    126 /mod HEX: 81 + swap
+    10 /mod HEX: 30 + swap
     HEX: 81 +
-    B{ } 4sequence reverse ;
+    B{ } 4sequence dup reverse-here ;
 
 : >interval-map-by ( start-quot end-quot value-quot seq -- interval-map )
     '[ _ [ @ 2array ] _ tri ] { } map>assoc <interval-map> ; inline

! Resource file from:
! http://source.icu-project.org/repos/icu/data/trunk/charset/data/xml/gb-18030-2000.xml

TUPLE: range ufirst ulast bfirst blast ;

: b>byte-array ( string -- byte-array )

    [ ufirst>> ] [ ulast>> ] [ ] >interval-map-by ;

: ranges-gb>u ( ranges -- interval-map )
    [ bfirst>> ] [ blast>> ] [ ] >interval-map-by ;

VALUE: gb>u
VALUE: u>gb
