зеркало из https://github.com/mozilla/pjs.git
add new method to case conversion so we can handle special casing ( SS or turiksh dotless I)
This commit is contained in:
Родитель
86711491f1
Коммит
43b49d0092
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "nsISupports.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// {07D3D8E0-9614-11d2-B3AD-00805F8A6670}
|
||||
#define NS_ICASECONVERSION_IID \
|
||||
|
@ -55,6 +56,11 @@ public:
|
|||
// Convert an array of Unicode characters into title case
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -333,6 +333,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.SetString(anIn,aLen);
|
||||
|
||||
// Special casing - Turkish dotless I
|
||||
if((nsnull != aLocale ) && (PRUnichar('t')==aLocale[0]) && (PRUnichar('r') == aLocale[1]))
|
||||
{
|
||||
for(PRUnichar* s=(PRUnichar*)anOut.GetUnicode(); *s ; s++)
|
||||
{
|
||||
if(kDot_i == *s)
|
||||
*s = kDot_I;
|
||||
}
|
||||
}
|
||||
|
||||
ToUpper(anOut.GetUnicode(), (PRUnichar*)anOut.GetUnicode(), anOut.Length());
|
||||
|
||||
// Special casing - SS
|
||||
PRInt32 idx=0;
|
||||
for(PRUnichar* s=(PRUnichar*)anOut.GetUnicode(); *s ; s++,idx++)
|
||||
{
|
||||
if(k_ss == *s) {
|
||||
*s = PRUnichar('S') ;
|
||||
anOut.Insert(PRUnichar('S'),idx);
|
||||
// Insert may cause reallocate, so we need to GetUnicode() again
|
||||
s = (PRUnichar*)anOut.GetUnicode() + idx;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsCaseConversionImp2::ToLower
|
||||
(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale)
|
||||
{
|
||||
anOut.SetString(anIn,aLen);
|
||||
|
||||
// Special casing - Turkish dotless I
|
||||
if((nsnull != aLocale ) && (PRUnichar('t')==aLocale[0]) && (PRUnichar('r') == aLocale[1]))
|
||||
{
|
||||
for(PRUnichar* s=(PRUnichar*)anOut.GetUnicode(); *s ; s++)
|
||||
{
|
||||
if(kDot_I == *s)
|
||||
*s = kDot_I;
|
||||
}
|
||||
}
|
||||
|
||||
ToLower(anOut.GetUnicode(), (PRUnichar*)anOut.GetUnicode(), anOut.Length());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsCaseConversionImp2::ToTitle
|
||||
(const PRUnichar* anIn, PRUint32 aLen, nsString& anOut, const PRUnichar* aLocale,
|
||||
PRBool aStartInWordBoundary)
|
||||
{
|
||||
anOut.SetString(anIn,aLen);
|
||||
|
||||
// Special casing - Turkish dotless I
|
||||
if((nsnull != aLocale ) && (PRUnichar('t')==aLocale[0]) && (PRUnichar('r') == aLocale[1]))
|
||||
{
|
||||
for(PRUnichar* s=(PRUnichar*)anOut.GetUnicode(); *s ; s++)
|
||||
{
|
||||
if(kDot_i == *s)
|
||||
*s = kDot_I;
|
||||
}
|
||||
}
|
||||
|
||||
ToTitle(anOut.GetUnicode(), (PRUnichar*)anOut.GetUnicode(), anOut.Length(),
|
||||
aStartInWordBoundary);
|
||||
|
||||
// Special casing - SS
|
||||
PRInt32 idx=0;
|
||||
for(PRUnichar* s=(PRUnichar*)anOut.GetUnicode(); *s ; s++,idx++)
|
||||
{
|
||||
if(k_ss == *s) {
|
||||
*s = PRUnichar('S') ;
|
||||
anOut.Insert(PRUnichar('S'),idx);
|
||||
// Insert may cause reallocate, so we need to GetUnicode() again
|
||||
s = (PRUnichar*)anOut.GetUnicode() + idx;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsCaseConversionImp2::nsCaseConversionImp2()
|
||||
|
|
|
@ -51,6 +51,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) ;
|
||||
private:
|
||||
static nsrefcnt gInit;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче