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

Method split

src/String.cpp:2001–2101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1999}
2000
2001Array<String> String::split(const String &inDelimiter) const
2002{
2003 int len = inDelimiter.length;
2004 int pos = 0;
2005 int last = 0;
2006 if (len==0)
2007 {
2008 // Special case of splitting into characters - use efficient code...
2009 int chars = length;
2010 Array<String> result(0,chars);
2011 int idx = 0;
2012 #ifdef HX_SMART_STRINGS
2013 if (isUTF16Encoded())
2014 {
2015 const char16_t *p = __w;
2016 for(int i=0;i<length;i++)
2017 result[i] = String::fromCharCode(p[i]);
2018 /*
2019 const char16_t *end = p + length;
2020 while(p<end)
2021 result[idx++] = String::fromCharCode(Char16Advance(p));
2022 */
2023 }
2024 else
2025 {
2026 for(int i=0;i<chars;i++)
2027 result[i] = String::fromCharCode( __s[i] );
2028 }
2029 #else
2030 for(int i=0;i<chars; )
2031 {
2032 const unsigned char *start = (const unsigned char *)(__s + i);
2033 const unsigned char *ptr = start;
2034 DecodeAdvanceUTF8(ptr);
2035 int len = ptr - start;
2036 result[idx++] = String::create( __s+i, len );
2037 i+=len;
2038 }
2039 #endif
2040 return result;
2041 }
2042
2043
2044 Array<String> result(0,1);
2045 #if HX_SMART_STRINGS
2046 bool s0 = isUTF16Encoded();
2047 bool s1 = inDelimiter.isUTF16Encoded();
2048 if (s0 || s1)
2049 {
2050 if (s0 && s1)
2051 {
2052 while(pos+len <=length )
2053 if (!memcmp(__w+pos,inDelimiter.__w,len*2))
2054 {
2055 result->push( substr(last,pos-last) );
2056 pos += len;
2057 last = pos;
2058 }

Callers 4

linkTypesMethod · 0.80
TypeDataMethod · 0.80
runObjectMethod · 0.80
runSplitMethod · 0.80

Calls 6

isUTF16EncodedFunction · 0.85
DecodeAdvanceUTF8Function · 0.85
isSameFunction · 0.85
memcmpFunction · 0.50
nullClass · 0.50
pushMethod · 0.45

Tested by

no test coverage detected