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

Method wchar_str

src/String.cpp:1920–1979  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1918}
1919
1920const wchar_t * String::wchar_str(hx::IStringAlloc *inBuffer) const
1921{
1922 if (!__s)
1923 return 0;
1924 if (length==0)
1925 return L"";
1926
1927 #ifdef HX_SMART_STRINGS
1928 if (isUTF16Encoded())
1929 {
1930 if (sizeof(wchar_t)==sizeof(char16_t))
1931 return (wchar_t *)__w;
1932 }
1933
1934 wchar_t *result = 0;
1935 if (inBuffer)
1936 {
1937 result = (wchar_t *)inBuffer->allocBytes(sizeof(wchar_t)*(length+1) );
1938 }
1939 else
1940 {
1941 result = (wchar_t *)NewGCPrivate(0,sizeof(wchar_t)*(length+1) );
1942 }
1943 if (isUTF16Encoded())
1944 for(int i=0;i<length;i++)
1945 result[i] = __w[i];
1946 else
1947 for(int i=0;i<length;i++)
1948 result[i] = __s[i];
1949 result[length] = 0;
1950 return result;
1951 #else
1952
1953 const unsigned char *ptr = (const unsigned char *)__s;
1954 const unsigned char *end = ptr + length;
1955 int idx = 0;
1956 while(ptr<end)
1957 {
1958 DecodeAdvanceUTF8(ptr,end);
1959 idx++;
1960 }
1961
1962 wchar_t *result = 0;
1963 if (inBuffer)
1964 {
1965 result = (wchar_t *)inBuffer->allocBytes(sizeof(wchar_t)*(idx+1) );
1966 }
1967 else
1968 {
1969 result = (wchar_t *)NewGCPrivate(0,sizeof(wchar_t)*(idx+1) );
1970 }
1971
1972 ptr = (const unsigned char *)__s;
1973 idx = 0;
1974 while(ptr<end)
1975 result[idx++] = DecodeAdvanceUTF8(ptr,end);
1976 result[idx] = 0;
1977 return result;

Callers 15

val_dup_wstringFunction · 0.80
hxs_wcharFunction · 0.80
_hx_std_get_envFunction · 0.80
_hx_std_put_envFunction · 0.80
_hx_std_set_time_localeFunction · 0.80
_hx_std_set_cwdFunction · 0.80
_hx_std_sys_commandFunction · 0.80
_hx_std_sys_existsFunction · 0.80
_hx_std_file_deleteFunction · 0.80
_hx_std_sys_renameFunction · 0.80
_hx_std_sys_statFunction · 0.80
_hx_std_sys_file_typeFunction · 0.80

Calls 4

isUTF16EncodedFunction · 0.85
NewGCPrivateFunction · 0.85
DecodeAdvanceUTF8Function · 0.85
allocBytesMethod · 0.45

Tested by

no test coverage detected