| 332 | |
| 333 | template<typename T> |
| 334 | static const char *GCStringDup(const T *inStr,int inLen, int *outLen=0) |
| 335 | { |
| 336 | if (inStr==0 && inLen<=0) |
| 337 | { |
| 338 | if (outLen) |
| 339 | outLen = 0; |
| 340 | return String::emptyString.raw_ptr(); |
| 341 | } |
| 342 | |
| 343 | int len = inLen; |
| 344 | bool allAscii = true; |
| 345 | if (len==-1) |
| 346 | { |
| 347 | len=0; |
| 348 | while(inStr[len]) |
| 349 | { |
| 350 | if (sizeof(T)>1 && allAscii) |
| 351 | allAscii = inStr[len] <= 127; |
| 352 | len++; |
| 353 | } |
| 354 | } |
| 355 | else if (sizeof(T)>1) |
| 356 | { |
| 357 | for(int i=0;i<inLen;i++) |
| 358 | if (inStr[i]>127) |
| 359 | { |
| 360 | allAscii = false; |
| 361 | break; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | if (outLen) |
| 366 | *outLen = len; |
| 367 | |
| 368 | if (len==1) |
| 369 | return String::fromCharCode(inStr[0]).raw_ptr(); |
| 370 | |
| 371 | #ifdef HXCPP_COMBINE_STRINGS |
| 372 | bool ident = len<20 && sIsIdent[inStr[0]] && (inStr[0]<'0' || inStr[0]>'9'); |
| 373 | if (ident && len>3) |
| 374 | for(int p=1; p<len;p++) |
| 375 | if (!sIsIdent[ inStr[p] ]) |
| 376 | { |
| 377 | ident = false; |
| 378 | break; |
| 379 | } |
| 380 | |
| 381 | if (ident) |
| 382 | { |
| 383 | hx::StackContext *ctx = hx::StackContext::getCurrent(); |
| 384 | if (!ctx->stringSet) |
| 385 | ctx->stringSet = new WeakStringSet(); |
| 386 | |
| 387 | unsigned int hash = 0; |
| 388 | for(int i=0;i<len;i++) |
| 389 | hash = hash*223 + ((unsigned char *)inStr)[i]; |
| 390 | |
| 391 | struct Finder |
no test coverage detected