| 1918 | } |
| 1919 | |
| 1920 | const 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; |
no test coverage detected