< prev index next >

src/jdk.jpackage/share/native/libapplauncher/PlatformString.cpp

Print this page

        

*** 23,33 **** * questions. */ #include "PlatformString.h" - #include "JavaTypes.h" #include "Helpers.h" #include <stdio.h> #include <stdlib.h> #include <stdlib.h> --- 23,32 ----
*** 35,116 **** #include <sstream> #include <string.h> #include "jni.h" - #ifdef MAC - StringToFileSystemString::StringToFileSystemString(const TString &value) { - FRelease = false; - PlatformString lvalue = PlatformString(value); - Platform& platform = Platform::GetInstance(); - FData = platform.ConvertStringToFileSystemString(lvalue, FRelease); - } - - StringToFileSystemString::~StringToFileSystemString() { - if (FRelease == true) { - delete[] FData; - } - } - - StringToFileSystemString::operator TCHAR* () { - return FData; - } - #endif //MAC - - #ifdef MAC - FileSystemStringToString::FileSystemStringToString(const TCHAR* value) { - bool release = false; - PlatformString lvalue = PlatformString(value); - Platform& platform = Platform::GetInstance(); - TCHAR* buffer = platform.ConvertFileSystemStringToString(lvalue, release); - FData = buffer; - - if (buffer != NULL && release == true) { - delete[] buffer; - } - } - - FileSystemStringToString::operator TString () { - return FData; - } - #endif //MAC - - void PlatformString::initialize() { FWideTStringToFree = NULL; FLength = 0; FData = NULL; } - void PlatformString::CopyString(char *Destination, - size_t NumberOfElements, const char *Source) { - #ifdef WINDOWS - strcpy_s(Destination, NumberOfElements, Source); - #endif //WINDOWS - #ifdef POSIX - strncpy(Destination, Source, NumberOfElements); - #endif //POSIX - - if (NumberOfElements > 0) { - Destination[NumberOfElements - 1] = '\0'; - } - } - - void PlatformString::CopyString(wchar_t *Destination, - size_t NumberOfElements, const wchar_t *Source) { - #ifdef WINDOWS - wcscpy_s(Destination, NumberOfElements, Source); - #endif //WINDOWS - #ifdef POSIX - wcsncpy(Destination, Source, NumberOfElements); - #endif //POSIX - - if (NumberOfElements > 0) { - Destination[NumberOfElements - 1] = '\0'; - } - } - PlatformString::PlatformString(void) { initialize(); } PlatformString::~PlatformString(void) { --- 34,49 ----
*** 121,205 **** if (FWideTStringToFree != NULL) { delete[] FWideTStringToFree; } } - // Owner must free the return value. - MultibyteString PlatformString::WideStringToMultibyteString( - const wchar_t* value) { - MultibyteString result; - size_t count = 0; - - if (value == NULL) { - return result; - } - - #ifdef WINDOWS - count = WideCharToMultiByte(CP_UTF8, 0, value, -1, NULL, 0, NULL, NULL); - - if (count > 0) { - result.data = new char[count + 1]; - result.length = WideCharToMultiByte(CP_UTF8, 0, value, -1, - result.data, (int)count, NULL, NULL); - #endif //WINDOWS - - #ifdef POSIX - count = wcstombs(NULL, value, 0); - - if (count > 0) { - result.data = new char[count + 1]; - result.data[count] = '\0'; - result.length = count; - wcstombs(result.data, value, count); - #endif //POSIX - } - - return result; - } - - // Owner must free the return value. - WideString PlatformString::MultibyteStringToWideString(const char* value) { - WideString result; - size_t count = 0; - - if (value == NULL) { - return result; - } - - #ifdef WINDOWS - mbstowcs_s(&count, NULL, 0, value, _TRUNCATE); - - if (count > 0) { - result.data = new wchar_t[count + 1]; - mbstowcs_s(&result.length, result.data, count, value, count); - #endif // WINDOWS - #ifdef POSIX - count = mbstowcs(NULL, value, 0); - - if (count > 0) { - result.data = new wchar_t[count + 1]; - result.data[count] = '\0'; - result.length = count; - mbstowcs(result.data, value, count); - #endif //POSIX - } - - return result; - } - PlatformString::PlatformString(const PlatformString &value) { initialize(); FLength = value.FLength; FData = new char[FLength + 1]; ! PlatformString::CopyString(FData, FLength + 1, value.FData); } PlatformString::PlatformString(const char* value) { initialize(); FLength = strlen(value); FData = new char[FLength + 1]; ! PlatformString::CopyString(FData, FLength + 1, value); } PlatformString::PlatformString(size_t Value) { initialize(); --- 54,75 ---- if (FWideTStringToFree != NULL) { delete[] FWideTStringToFree; } } PlatformString::PlatformString(const PlatformString &value) { initialize(); FLength = value.FLength; FData = new char[FLength + 1]; ! Platform::CopyString(FData, FLength + 1, value.FData); } PlatformString::PlatformString(const char* value) { initialize(); FLength = strlen(value); FData = new char[FLength + 1]; ! Platform::CopyString(FData, FLength + 1, value); } PlatformString::PlatformString(size_t Value) { initialize();
*** 208,272 **** ss << Value; s = ss.str(); FLength = strlen(s.c_str()); FData = new char[FLength + 1]; ! PlatformString::CopyString(FData, FLength + 1, s.c_str()); } PlatformString::PlatformString(const wchar_t* value) { initialize(); ! MultibyteString temp = WideStringToMultibyteString(value); FLength = temp.length; FData = temp.data; } PlatformString::PlatformString(const std::string &value) { initialize(); const char* lvalue = value.data(); FLength = value.size(); FData = new char[FLength + 1]; ! PlatformString::CopyString(FData, FLength + 1, lvalue); } PlatformString::PlatformString(const std::wstring &value) { initialize(); const wchar_t* lvalue = value.data(); ! MultibyteString temp = WideStringToMultibyteString(lvalue); FLength = temp.length; FData = temp.data; } - PlatformString::PlatformString(JNIEnv *env, jstring value) { - initialize(); - - if (env != NULL) { - const char* lvalue = env->GetStringUTFChars(value, JNI_FALSE); - - if (lvalue == NULL || env->ExceptionCheck() == JNI_TRUE) { - throw JavaException(); - } - - if (lvalue != NULL) { - FLength = env->GetStringUTFLength(value); - - if (env->ExceptionCheck() == JNI_TRUE) { - throw JavaException(); - } - - FData = new char[FLength + 1]; - PlatformString::CopyString(FData, FLength + 1, lvalue); - - env->ReleaseStringUTFChars(value, lvalue); - - if (env->ExceptionCheck() == JNI_TRUE) { - throw JavaException(); - } - } - } - } - TString PlatformString::Format(const TString value, ...) { TString result = value; va_list arglist; va_start(arglist, value); --- 78,113 ---- ss << Value; s = ss.str(); FLength = strlen(s.c_str()); FData = new char[FLength + 1]; ! Platform::CopyString(FData, FLength + 1, s.c_str()); } PlatformString::PlatformString(const wchar_t* value) { initialize(); ! MultibyteString temp = Platform::WideStringToMultibyteString(value); FLength = temp.length; FData = temp.data; } PlatformString::PlatformString(const std::string &value) { initialize(); const char* lvalue = value.data(); FLength = value.size(); FData = new char[FLength + 1]; ! Platform::CopyString(FData, FLength + 1, lvalue); } PlatformString::PlatformString(const std::wstring &value) { initialize(); const wchar_t* lvalue = value.data(); ! MultibyteString temp = Platform::WideStringToMultibyteString(lvalue); FLength = temp.length; FData = temp.data; } TString PlatformString::Format(const TString value, ...) { TString result = value; va_list arglist; va_start(arglist, value);
*** 305,315 **** char* PlatformString::toMultibyte() { return FData; } wchar_t* PlatformString::toWideString() { ! WideString result = MultibyteStringToWideString(FData); if (result.data != NULL) { if (FWideTStringToFree != NULL) { delete [] FWideTStringToFree; } --- 146,156 ---- char* PlatformString::toMultibyte() { return FData; } wchar_t* PlatformString::toWideString() { ! WideString result = Platform::MultibyteStringToWideString(FData); if (result.data != NULL) { if (FWideTStringToFree != NULL) { delete [] FWideTStringToFree; }
*** 341,364 **** } return result; } - jstring PlatformString::toJString(JNIEnv *env) { - jstring result = NULL; - - if (env != NULL) { - result = env->NewStringUTF(c_str()); - - if (result == NULL || env->ExceptionCheck() == JNI_TRUE) { - throw JavaException(); - } - } - - return result; - } - TCHAR* PlatformString::toPlatformString() { #ifdef _UNICODE return toWideString(); #else return c_str(); --- 182,191 ----
*** 386,400 **** } char* PlatformString::duplicate(const char* Value) { size_t length = strlen(Value); char* result = new char[length + 1]; ! PlatformString::CopyString(result, length + 1, Value); return result; } wchar_t* PlatformString::duplicate(const wchar_t* Value) { size_t length = wcslen(Value); wchar_t* result = new wchar_t[length + 1]; ! PlatformString::CopyString(result, length + 1, Value); return result; } --- 213,227 ---- } char* PlatformString::duplicate(const char* Value) { size_t length = strlen(Value); char* result = new char[length + 1]; ! Platform::CopyString(result, length + 1, Value); return result; } wchar_t* PlatformString::duplicate(const wchar_t* Value) { size_t length = wcslen(Value); wchar_t* result = new wchar_t[length + 1]; ! Platform::CopyString(result, length + 1, Value); return result; }
< prev index next >