Ticket #695: Integer-unicode.patch
File Integer-unicode.patch, 2.4 kB (added by Deewiant, 16 years ago) |
---|
patch for Integer |
-
Integer.d
old new 24 24 module tango.text.convert.Integer; 25 25 26 26 private import tango.core.Exception; 27 private import tango.text.convert.Utf : toString, toString16; 27 28 28 29 /****************************************************************************** 29 30 … … 39 40 Hex = 'x', /// lowercase hexadecimal 40 41 HexUpper = 'X', /// uppercase hexadecimal 41 42 Unsigned = 'u', /// unsigned integer 43 Unicode = 'c', /// Unicode code point 42 44 } 43 45 44 46 /****************************************************************************** … … 255 257 prefix = "0X"; 256 258 break; 257 259 260 case 'c': 261 if (i > dchar.max) 262 return error(cast(T[])"{code point outside valid range}"); 263 264 auto codepoint = cast(dchar)i; 265 dchar[1] str; 266 str[0] = codepoint; 267 268 static if (is(T == dchar)) { 269 dst[0] = codepoint; 270 return dst[0..1]; 271 } else { 272 uint eaten = 0; 273 T[] result = void; 274 275 static if (is(T == wchar)) 276 result = toString16(str, dst, &eaten); 277 else static if (is(T == char)) 278 result = toString(str, dst, &eaten); 279 else 280 static assert (false, "won't write Unicode to unknown buffer type"); 281 282 if (eaten) 283 return result; 284 else 285 goto noroom; 286 } 287 258 288 default: 259 289 return error (cast(T[])"{unknown format '"~cast(T)fmt~"'}"); 260 290 } … … 292 322 // write optional prefix string ... 293 323 dst [len .. len + prefix.length] = prefix[]; 294 324 } 295 else 325 else noroom: 296 326 return error ("{output width too small}"); 297 327 298 328 // return slice of provided output buffer