From 04cfa0ed7bd0aaa07998ecd51bd69c682cf59486 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Sat, 26 Feb 2000 02:19:34 +0000 Subject: [PATCH] Fix PDT+ bug # 6770: be able to get filenames from the file system in the platform native charset. Patch from m_kato@ga2.so-net.ne.jp Review: ftang, dougt, and myself. Approval: jar git-svn-id: svn://10.0.0.236/trunk@61723 18797224-902f-48f8-a5cc-f745e15eee43 --- .../datasource/src/nsFileSystemDataSource.cpp | 9 +---- mozilla/xpcom/io/nsFileSpec.cpp | 37 ++++++++++++++++++- mozilla/xpcom/io/nsFileSpec.h | 5 ++- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp b/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp index 1c35904c8e9..71752e9b424 100644 --- a/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp +++ b/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp @@ -1111,12 +1111,8 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult) nsFileURL url(uri); nsNativeFileSpec native(url); - char *baseFilename = native.GetLeafName(); - - if (! baseFilename) - return NS_ERROR_OUT_OF_MEMORY; - - nsAutoString name(baseFilename); + nsAutoString name; + native.GetLeafName(name); #ifdef XP_WIN @@ -1168,7 +1164,6 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult) nsIRDFLiteral *literal; gRDFService->GetLiteral(name.GetUnicode(), &literal); *aResult = literal; - nsCRT::free(baseFilename); return NS_OK; } diff --git a/mozilla/xpcom/io/nsFileSpec.cpp b/mozilla/xpcom/io/nsFileSpec.cpp index 705c1e3e1fc..2307c2194ee 100644 --- a/mozilla/xpcom/io/nsFileSpec.cpp +++ b/mozilla/xpcom/io/nsFileSpec.cpp @@ -41,6 +41,10 @@ #include #include +#ifdef XP_PC +#include +#endif + #ifdef XP_MAC #include #include @@ -353,8 +357,11 @@ char* nsSimpleCharString::GetLeaf(char inSeparator) const return nsnull; char* chars = mData->mString; +#ifdef XP_PC + const char* lastSeparator = (const char*) _mbsrchr((const unsigned char *) chars, inSeparator); +#else const char* lastSeparator = strrchr(chars, inSeparator); - +#endif // If there was no separator, then return a copy of our path. if (!lastSeparator) return nsCRT::strdup(*this); @@ -367,7 +374,11 @@ char* nsSimpleCharString::GetLeaf(char inSeparator) const // So now, separator was the last character. Poke in a null instead. *(char*)lastSeparator = '\0'; // Should use const_cast, but Unix has old compiler. +#ifdef XP_PC + leafPointer = (const char*) _mbsrchr((const unsigned char *) chars, inSeparator); +#else leafPointer = strrchr(chars, inSeparator); +#endif char* result = leafPointer ? nsCRT::strdup(++leafPointer) : nsCRT::strdup(chars); // Restore the poked null before returning. *(char*)lastSeparator = inSeparator; @@ -1195,7 +1206,29 @@ void nsFileSpec::GetNativePathString(nsString &nativePathString) } } - + +//---------------------------------------------------------------------------------------- +void nsFileSpec::GetLeafName(nsString &nativePathString) +//---------------------------------------------------------------------------------------- +{ + char * path = GetLeafName(); + if (nsnull == path) { + nativePathString.SetString(""); + return; + } else { + PRUnichar *converted = ConvertFromFileSystemCharset(path); + if (nsnull != converted) { + nativePathString.SetString(converted); + delete [] converted; + } + else + nativePathString.SetString(path); + + nsCRT::free(path); + } +} + + #ifdef XP_MAC #pragma mark - #endif diff --git a/mozilla/xpcom/io/nsFileSpec.h b/mozilla/xpcom/io/nsFileSpec.h index 646a0c1b61f..cdff500bcbc 100644 --- a/mozilla/xpcom/io/nsFileSpec.h +++ b/mozilla/xpcom/io/nsFileSpec.h @@ -409,7 +409,10 @@ class NS_COM nsFileSpec //-------------------------------------------------- char* GetLeafName() const; // Allocated. Use nsCRT::free(). - + + // Unicode version of GetLeafName() + void GetLeafName(nsString &nativePathString); + #if 0 // needs implementing // copy the leaf name into the supplied buffer, thus