@@ -2028,53 +2028,68 @@ bindNative(["cn1_java_lang_String_charsToBytes_char_1ARRAY_char_1ARRAY_R_byte_1A
20282028 return out ;
20292029} ) ;
20302030bindNative ( [ "cn1_java_lang_String_format_java_lang_String_java_lang_Object_1ARRAY_R_java_lang_String" ] , function * ( format , args ) {
2031- let index = 0 ;
2031+ const text = jvm . toNativeString ( format ) ;
20322032 const values = [ ] ;
20332033 if ( args && args . __array ) {
20342034 for ( let i = 0 ; i < args . length ; i ++ ) {
20352035 values . push ( args [ i ] ) ;
20362036 }
20372037 }
2038- const result = jvm . toNativeString ( format ) . replace ( / % [ % s d i f c ] / g, function ( token ) {
2039- if ( token === "%%" ) {
2040- return "%" ;
2038+
2039+ const nextArgString = function * ( token ) {
2040+ const arg = values . length ? values . shift ( ) : null ;
2041+ if ( token === "c" ) {
2042+ const native = yield * runtimeToNativeString ( arg ) ;
2043+ if ( native == null || native . length === 0 ) {
2044+ return "" ;
2045+ }
2046+ if ( native . length === 1 ) {
2047+ return native ;
2048+ }
2049+ const asInt = parseInt ( native , 10 ) ;
2050+ return isNaN ( asInt ) ? native . charAt ( 0 ) : String . fromCharCode ( asInt ) ;
20412051 }
2042- const value = values [ index ++ ] ;
2043- return {
2044- __token : token ,
2045- __value : value
2046- } ;
2047- } ) . replace ( / \[ o b j e c t O b j e c t \] / g, function ( ) {
2048- return "" ;
2049- } ) ;
2050- let expanded = "" ;
2051- let start = 0 ;
2052- const pattern = / ( \{ \} | \[ o b j e c t O b j e c t \] ) / g;
2053- const placeholderMatches = [ ] ;
2054- jvm . toNativeString ( format ) . replace ( / % [ % s d i f c ] / g, function ( token ) {
2055- if ( token !== "%%" ) {
2056- placeholderMatches . push ( token ) ;
2057- }
2058- return token ;
2059- } ) ;
2060- const pieces = jvm . toNativeString ( format ) . split ( / % [ % s d i f c ] / g) ;
2061- const tokens = [ ] ;
2062- jvm . toNativeString ( format ) . replace ( / % [ % s d i f c ] / g, function ( token ) {
2063- tokens . push ( token ) ;
2064- return token ;
2065- } ) ;
2066- for ( let i = 0 ; i < pieces . length ; i ++ ) {
2067- expanded += pieces [ i ] ;
2068- if ( i < tokens . length ) {
2069- const token = tokens [ i ] ;
2070- if ( token === "%%" ) {
2071- expanded += "%" ;
2072- } else {
2073- expanded += yield * runtimeFormatTokenValue ( token , values [ start ++ ] ) ;
2052+ return yield * runtimeToNativeString ( arg ) ;
2053+ } ;
2054+
2055+ let out = "" ;
2056+ for ( let i = 0 ; i < text . length ; i ++ ) {
2057+ const ch = text . charAt ( i ) ;
2058+ if ( ch !== "%" || i === text . length - 1 ) {
2059+ out += ch ;
2060+ continue ;
2061+ }
2062+
2063+ const next = text . charAt ( i + 1 ) ;
2064+ if ( next === "%" ) {
2065+ out += "%" ;
2066+ i ++ ;
2067+ continue ;
2068+ }
2069+
2070+ let j = i + 1 ;
2071+ while ( j < text . length && "-#+ 0,(" . indexOf ( text . charAt ( j ) ) >= 0 ) {
2072+ j ++ ;
2073+ }
2074+ while ( j < text . length && text . charAt ( j ) >= "0" && text . charAt ( j ) <= "9" ) {
2075+ j ++ ;
2076+ }
2077+ if ( j < text . length && text . charAt ( j ) === "." ) {
2078+ j ++ ;
2079+ while ( j < text . length && text . charAt ( j ) >= "0" && text . charAt ( j ) <= "9" ) {
2080+ j ++ ;
20742081 }
20752082 }
2083+ const token = j < text . length ? text . charAt ( j ) : "" ;
2084+ if ( "sdifc" . indexOf ( token ) >= 0 ) {
2085+ out += yield * nextArgString ( token ) ;
2086+ i = j ;
2087+ } else {
2088+ out += "%" ;
2089+ }
20762090 }
2077- return createJavaString ( expanded ) ;
2091+
2092+ return createJavaString ( out ) ;
20782093} ) ;
20792094bindNative ( [ "cn1_java_lang_StringToReal_parseDblImpl_java_lang_String_int_R_double" ] , function * ( value , exponentIndex ) {
20802095 const text = jvm . toNativeString ( value ) ;
0 commit comments