MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / GCStringDup

Function GCStringDup

src/String.cpp:334–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332
333template<typename T>
334static 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

Callers 7

TCopyStringFunction · 0.85
createMethod · 0.85
fromIntMethod · 0.85
StringMethod · 0.85
fromPointerMethod · 0.85
__hxcpp_string_of_bytesFunction · 0.85
substrMethod · 0.85

Calls 7

NewStringFunction · 0.85
memcpyFunction · 0.85
IsUtf16LowSurrogateFunction · 0.85
IsUtf16HighSurrogateFunction · 0.85
findEquivalentKeyMethod · 0.80
TSetMethod · 0.80
FinderClass · 0.70

Tested by

no test coverage detected