From 9c629f6331244e9815545e19b9bb32b9b3507380 Mon Sep 17 00:00:00 2001 From: "smontagu%smontagu.org" Date: Wed, 21 Jan 2004 08:06:12 +0000 Subject: [PATCH] Backing out last change because of test failures on tinderbox. --- intl/unicharutil/public/nsICaseConversion.h | 5 ++ intl/unicharutil/src/nsCaseConversionImp2.cpp | 90 +++++++++++++++++++ intl/unicharutil/src/nsCaseConversionImp2.h | 3 + 3 files changed, 98 insertions(+) diff --git a/intl/unicharutil/public/nsICaseConversion.h b/intl/unicharutil/public/nsICaseConversion.h index 80273b9b649..7e3ec63f23c 100644 --- a/intl/unicharutil/public/nsICaseConversion.h +++ b/intl/unicharutil/public/nsICaseConversion.h @@ -73,6 +73,11 @@ public: NS_IMETHOD ToTitle( const PRUnichar* anArray, PRUnichar* aReturn, PRUint32 aLen, PRBool aStartInWordBundary=PR_TRUE) = 0; + // The following nsString flavor one know how to handle special casing + NS_IMETHOD ToUpper(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale=nsnull) = 0; + NS_IMETHOD ToLower(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale=nsnull ) = 0; + NS_IMETHOD ToTitle(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale=nsnull, PRBool aStartInWordBoundary=PR_TRUE) = 0; + // case-insensitive PRUnichar* comparison - aResult returns similar // to strcasecmp NS_IMETHOD CaseInsensitiveCompare(const PRUnichar* aLeft, const PRUnichar* aRight, PRUint32 aLength, PRInt32* aResult) = 0; diff --git a/intl/unicharutil/src/nsCaseConversionImp2.cpp b/intl/unicharutil/src/nsCaseConversionImp2.cpp index f63be840da2..45b70b877cf 100644 --- a/intl/unicharutil/src/nsCaseConversionImp2.cpp +++ b/intl/unicharutil/src/nsCaseConversionImp2.cpp @@ -340,6 +340,96 @@ nsresult nsCaseConversionImp2::ToTitle( return NS_OK; } +#define k_ss 0x00df +#define kDot_I 0x0130 +#define kDot_i PRUnichar('i') +#define kDotLess_I PRUnichar('I') +#define kDotLess_i 0x0131 + +NS_IMETHODIMP nsCaseConversionImp2::ToUpper + (const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale) +{ + anOut.Assign(anIn,aLen); + + // Special casing - Turkish dotless I + if((nsnull != aLocale ) && (PRUnichar('t')==aLocale[0]) && (PRUnichar('r') == aLocale[1])) + { + for(PRUnichar* s=(PRUnichar*)anOut.get(); *s ; s++) + { + if(kDot_i == *s) + *s = kDot_I; + } + } + + ToUpper(anOut.get(), (PRUnichar*)anOut.get(), anOut.Length()); + + // Special casing - SS + PRInt32 idx=0; + for(PRUnichar* s=(PRUnichar*)anOut.get(); *s ; s++,idx++) + { + if(k_ss == *s) { + *s = PRUnichar('S') ; + anOut.Insert(PRUnichar('S'),idx); + // Insert may cause reallocate, so we need to get() again + s = (PRUnichar*)anOut.get() + idx; + idx++; + } + } + return NS_OK; +} +NS_IMETHODIMP nsCaseConversionImp2::ToLower + (const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale) +{ + anOut.Assign(anIn,aLen); + + // Special casing - Turkish dotless I + if((nsnull != aLocale ) && (PRUnichar('t')==aLocale[0]) && (PRUnichar('r') == aLocale[1])) + { + for(PRUnichar* s=(PRUnichar*)anOut.get(); *s ; s++) + { + if(kDot_I == *s) + *s = kDot_I; + } + } + + ToLower(anOut.get(), (PRUnichar*)anOut.get(), anOut.Length()); + + return NS_OK; +} +NS_IMETHODIMP nsCaseConversionImp2::ToTitle + (const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale, + PRBool aStartInWordBoundary) +{ + anOut.Assign(anIn,aLen); + + // Special casing - Turkish dotless I + if((nsnull != aLocale ) && (PRUnichar('t')==aLocale[0]) && (PRUnichar('r') == aLocale[1])) + { + for(PRUnichar* s=(PRUnichar*)anOut.get(); *s ; s++) + { + if(kDot_i == *s) + *s = kDot_I; + } + } + + ToTitle(anOut.get(), (PRUnichar*)anOut.get(), anOut.Length(), + aStartInWordBoundary); + + // Special casing - SS + PRInt32 idx=0; + for(PRUnichar* s=(PRUnichar*)anOut.get(); *s ; s++,idx++) + { + if(k_ss == *s) { + *s = PRUnichar('S') ; + anOut.Insert(PRUnichar('S'),idx); + // Insert may cause reallocate, so we need to get() again + s = (PRUnichar*)anOut.get() + idx; + idx++; + } + } + return NS_OK; +} + // implementation moved from the old nsCRT routine NS_IMETHODIMP nsCaseConversionImp2::CaseInsensitiveCompare(const PRUnichar *aLeft, diff --git a/intl/unicharutil/src/nsCaseConversionImp2.h b/intl/unicharutil/src/nsCaseConversionImp2.h index b9baa3731c6..1189010d4c0 100644 --- a/intl/unicharutil/src/nsCaseConversionImp2.h +++ b/intl/unicharutil/src/nsCaseConversionImp2.h @@ -67,6 +67,9 @@ public: NS_IMETHOD ToTitle(const PRUnichar* anArray, PRUnichar* aReturn, PRUint32 aLen, PRBool aStartInWordBoundary = PR_TRUE); + NS_IMETHOD ToUpper(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale=nsnull) ; + NS_IMETHOD ToLower(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale=nsnull ); + NS_IMETHOD ToTitle(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale=nsnull, PRBool aStartInWordBoundary=PR_TRUE) ; NS_IMETHOD CaseInsensitiveCompare(const PRUnichar* aLeft, const PRUnichar* aRight, PRUint32 aLength, PRInt32 *aResult); private: static nsrefcnt gInit;