|
|
@ -108,7 +108,10 @@ namespace clix { |
|
|
|
typedef typename StringTypeSelector<encoding>::Type SourceStringType; |
|
|
|
typedef typename StringTypeSelector<encoding>::Type SourceStringType; |
|
|
|
size_t byteCount = cxxString.length() * sizeof(SourceStringType::value_type); |
|
|
|
size_t byteCount = cxxString.length() * sizeof(SourceStringType::value_type); |
|
|
|
|
|
|
|
|
|
|
|
if(byteCount == 0) return System::String::Empty; |
|
|
|
// Empty strings would cause trouble accessing the array below
|
|
|
|
|
|
|
|
if(byteCount == 0) { |
|
|
|
|
|
|
|
return System::String::Empty; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Copy the C++ string contents into a managed array of bytes
|
|
|
|
// Copy the C++ string contents into a managed array of bytes
|
|
|
|
array<unsigned char> ^bytes = gcnew array<unsigned char>(byteCount); |
|
|
|
array<unsigned char> ^bytes = gcnew array<unsigned char>(byteCount); |
|
|
@ -143,11 +146,14 @@ namespace clix { |
|
|
|
) { |
|
|
|
) { |
|
|
|
typedef typename StringTypeSelector<encoding>::Type StringType; |
|
|
|
typedef typename StringTypeSelector<encoding>::Type StringType; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Empty strings would cause a problem when accessing the empty managed array
|
|
|
|
|
|
|
|
if(!string || string->Length == 0) { |
|
|
|
|
|
|
|
return StringType(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// First, we use .NET's encoding classes to convert the string into a byte array
|
|
|
|
// First, we use .NET's encoding classes to convert the string into a byte array
|
|
|
|
array<unsigned char> ^bytes = encode<encoding>(string); |
|
|
|
array<unsigned char> ^bytes = encode<encoding>(string); |
|
|
|
|
|
|
|
|
|
|
|
if(bytes->Length == 0) return StringType(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Then we construct our native string from that byte array
|
|
|
|
// Then we construct our native string from that byte array
|
|
|
|
pin_ptr<unsigned char> pinnedBytes(&bytes[0]); |
|
|
|
pin_ptr<unsigned char> pinnedBytes(&bytes[0]); |
|
|
|
return StringType( |
|
|
|
return StringType( |
|
|
|