From 2d7bb61d3f8fc1f99431016e72761c8398bdb8a3 Mon Sep 17 00:00:00 2001 From: "ftang%netscape.com" Date: Fri, 21 Apr 2000 21:44:23 +0000 Subject: [PATCH] fix nsFileSpec unicode interface . git-svn-id: svn://10.0.0.236/trunk@66760 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsFileSpec.h | 43 +++------------- mozilla/xpcom/io/nsLocalFileCommon.cpp | 71 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 36 deletions(-) diff --git a/mozilla/xpcom/io/nsFileSpec.h b/mozilla/xpcom/io/nsFileSpec.h index ce85d57df90..61290512bb2 100644 --- a/mozilla/xpcom/io/nsFileSpec.h +++ b/mozilla/xpcom/io/nsFileSpec.h @@ -334,11 +334,7 @@ class NS_COM nsFileSpec // These two operands take *native* file paths. void operator = (const char* inNativePath); - void operator = (const nsString& inNativePath) - { - const nsAutoCString path(inNativePath); - *this = path; - } + void operator = (const nsString& inNativePath); void operator = (const nsFilePath& inPath); void operator = (const nsFileURL& inURL); @@ -436,11 +432,7 @@ class NS_COM nsFileSpec // inLeafName can be a relative path, so this allows // one kind of concatenation of "paths". void SetLeafName(const char* inLeafName); - void SetLeafName(const nsString& inLeafName) - { - const nsAutoCString leafName(inLeafName); - SetLeafName(leafName); - } + void SetLeafName(const nsString& inLeafName); // Return the filespec of the parent directory. Used // in conjunction with GetLeafName(), this lets you @@ -476,12 +468,7 @@ class NS_COM nsFileSpec PRInt64 GetDiskSpaceAvailable() const; nsFileSpec operator + (const char* inRelativeUnixPath) const; - nsFileSpec operator + (const nsString& inRelativeUnixPath) const - { - const nsAutoCString - relativePath(inRelativeUnixPath); - return *this + relativePath; - } + nsFileSpec operator + (const nsString& inRelativeUnixPath) const; // Concatenate the relative path to this directory. // Used for constructing the filespec of a descendant. @@ -493,19 +480,11 @@ class NS_COM nsFileSpec // "below" this. void operator += (const char* inRelativeUnixPath); - void operator += (const nsString& inRelativeUnixPath) - { - const nsAutoCString relativePath(inRelativeUnixPath); - *this += relativePath; - } + void operator += (const nsString& inRelativeUnixPath); void MakeUnique(); void MakeUnique(const char* inSuggestedLeafName); - void MakeUnique(const nsString& inSuggestedLeafName) - { - const nsAutoCString suggestedLeafName(inSuggestedLeafName); - MakeUnique(suggestedLeafName); - } + void MakeUnique(const nsString& inSuggestedLeafName); PRBool IsDirectory() const; // More stringent than Exists() @@ -532,19 +511,11 @@ class NS_COM nsFileSpec void RecursiveCopy(nsFileSpec newDir) const; nsresult Rename(const char* inNewName); // not const: gets updated - nsresult Rename(const nsString& inNewName) - { - const nsAutoCString newName(inNewName); - return Rename(newName); - } + nsresult Rename(const nsString& inNewName); nsresult CopyToDir(const nsFileSpec& inNewParentDirectory) const; nsresult MoveToDir(const nsFileSpec& inNewParentDirectory); nsresult Execute(const char* args) const; - nsresult Execute(const nsString& args) const - { - const nsAutoCString argsString(args); - return Execute(argsString); - } + nsresult Execute(const nsString& args) const; // Internal routine //-------------------------------------------------- diff --git a/mozilla/xpcom/io/nsLocalFileCommon.cpp b/mozilla/xpcom/io/nsLocalFileCommon.cpp index f17c26778d0..f666d7abace 100644 --- a/mozilla/xpcom/io/nsLocalFileCommon.cpp +++ b/mozilla/xpcom/io/nsLocalFileCommon.cpp @@ -27,6 +27,9 @@ #include "nsIUnicodeEncoder.h" #include "nsIUnicodeDecoder.h" +/* nsFileSpec stuff. put here untill it got obsoleted */ +#include "nsFileSpec.h" + #ifdef XP_PC #include "nsLocalFileWin.h" #endif @@ -70,6 +73,16 @@ private: } \ return res; \ } +#define VOID_SET_UCS( func , arg, assertion_msg) \ + { \ + char* tmp; \ + nsresult res; \ + if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((arg), &tmp))) { \ + (func)(tmp); \ + nsAllocator::Free(tmp); \ + } \ + NS_ASSERTION(NS_SUCCEEDED(res), assertion_msg); \ +} #define SET_UCS( func , arg) \ { \ char* tmp; \ @@ -266,3 +279,61 @@ NS_NewUnicodeLocalFile(const PRUnichar* path, nsILocalFile* *result) { SET_UCS_2ARGS_1( NS_NewLocalFile , path, result) } + +// ================================================================== +// nsFileSpec stuff . put here untill nsFileSpec get obsoleted +// ================================================================== + +void nsFileSpec::operator = (const nsString& inNativePath) +{ + char* tmp; + nsresult res; + if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((inNativePath.GetUnicode()), &tmp))) { + *this = tmp; + nsAllocator::Free(tmp); + } + mError = res; + NS_ASSERTION(NS_SUCCEEDED(res), "nsFileSpec = filed"); +} +nsFileSpec nsFileSpec::operator + (const nsString& inRelativeUnixPath) const +{ + nsFileSpec resultSpec; + char* tmp; + nsresult res; + if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((inRelativeUnixPath.GetUnicode()), &tmp))) { + resultSpec = *this; + resultSpec += tmp; + nsAllocator::Free(tmp); + } + NS_ASSERTION(NS_SUCCEEDED(res), "nsFileSpec + filed"); + return resultSpec; +} +void nsFileSpec::operator += (const nsString& inRelativeUnixPath) +{ + char* tmp; + nsresult res; + if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((inRelativeUnixPath.GetUnicode()), &tmp))) { + *this += tmp; + nsAllocator::Free(tmp); + } + mError = res; + NS_ASSERTION(NS_SUCCEEDED(res), "nsFileSpec + filed"); +} + +void nsFileSpec::SetLeafName (const nsString& inLeafName) +{ + VOID_SET_UCS( SetLeafName , inLeafName.GetUnicode(),"nsFileSpec::SetLeafName failed"); +} +void nsFileSpec::MakeUnique(const nsString& inSuggestedLeafName) +{ + VOID_SET_UCS( MakeUnique,inSuggestedLeafName.GetUnicode(),"nsFileSpec::MakeUnique failed"); +} +nsresult nsFileSpec::Rename(const nsString& inNewName) +{ + SET_UCS( Rename , inNewName.GetUnicode()); +} +nsresult nsFileSpec::Execute(const nsString& args) const +{ + SET_UCS( Execute , args.GetUnicode()); +} +