mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
check in prototype code for orderid formater
This commit is contained in:
parent
88fe8762de
commit
abb18bd6d6
33
intl/unicharutil/src/nsCharsList.h
Normal file
33
intl/unicharutil/src/nsCharsList.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsCharsList_h__
|
||||
#define nsCharsList_h__
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
class nsCharsList {
|
||||
|
||||
public:
|
||||
|
||||
virtual PRUnichar Get( PRUint32 aIdx) = 0;
|
||||
|
||||
virtual PRUint32 Length() = 0;
|
||||
};
|
||||
|
||||
#endif /* nsCharsList_h__ */
|
151
intl/unicharutil/src/nsCharsOrderIdFormater.cpp
Normal file
151
intl/unicharutil/src/nsCharsOrderIdFormater.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "pratom.h"
|
||||
#include "nsUUDll.h"
|
||||
#include "nsCharsOrderIdFormater.h"
|
||||
|
||||
|
||||
nsCharsOrderIdFormater::nsCharsOrderIdFormater( nsCharsList* aList)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
mList = aList;
|
||||
mBase = aList->Length();
|
||||
}
|
||||
|
||||
nsCharsOrderIdFormater::~nsCharsOrderIdFormater()
|
||||
{
|
||||
delete mList;
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
NS_IMETHOD ToString( PRUint32 aOrder, nsString& aResult)
|
||||
{
|
||||
aResult = "";
|
||||
|
||||
PRUint32 current;
|
||||
PRUint32 remain = aOrder;
|
||||
|
||||
do {
|
||||
current = aOrder % mBase;
|
||||
remain = aOrder / mBase;
|
||||
aResult.Insert(mList->Get(current),0);
|
||||
|
||||
} while( remain != 0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kIOrderIdFormaterIID, NS_IORDERIDFORMATER_IID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCharsOrderIdFormater, kIOrderIdFormaterIID);
|
||||
|
||||
class nsCharsOrderIdFormaterFactory : public nsIFactory {
|
||||
NS_DECL_ISUPPORTS
|
||||
public:
|
||||
nsCharsOrderIdFormaterFactory(const nsCID &aCID) {
|
||||
NS_INIT_REFCNT();
|
||||
PR_AutomicIncrement(&g_InstanceCount);
|
||||
mCID = aCID;
|
||||
};
|
||||
virtual ~nsCharsOrderIdFormaterFactory() {
|
||||
PR_AutomicDecrement(&g_InstanceCount);
|
||||
};
|
||||
NS_IMETHOD CreateInstance(nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
NS_IMETHOD LockFactory(PRBool aLock) {
|
||||
if(aLock)
|
||||
PR_AutomicIncrement(&g_LockCount);
|
||||
else
|
||||
PR_AutomicDecrement(&g_LockCount);
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
private:
|
||||
nsCID mCID;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCharsOrderIdFormaterFactory, kFactoryIID);
|
||||
NS_IMETHODIMP nsCharsOrderIdFormaterFactory::CreateInstance(
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if(NULL == aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*aResult = NULL;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
if(mCID.Equals(kLowerAToZOrderIdCID)) {
|
||||
inst = new nsCharOrderIdFormater(new nsRangeCharsList('a', 'z'));
|
||||
} else if(mCID.Equals(kUpperAToZOrderIdCID)) {
|
||||
inst = new nsCharOrderIdFormater(new nsRangeCharsList('A', 'Z'));
|
||||
} else if(mCID.Equals(k0To9OrderIdCID)) {
|
||||
inst = new nsCharOrderIdFormater(new nsRangeCharsList('0', '9'));
|
||||
} else if(mCID.Equals(kHeavenlyStemOrderIdCID)) {
|
||||
static PRUnichar gHeavenlyStemList[] = {
|
||||
0x7532, 0x4e59, 0x4e19, 0x4e01, 0x620a,
|
||||
0x5df1, 0x5e9a, 0x8f9b, 0x58ce, 0x7678
|
||||
};
|
||||
nsAutoString tmp(gHeavenlyStemList,
|
||||
sizeof(gHeavenlyStemList)/sizeof(PRUnichar));
|
||||
inst = new nsCharOrderIdFormater(new nsStringCharsList(tmp));
|
||||
} else if(mCID.Equals(kEarthlyBranchOrderIdCID)) {
|
||||
static PRUnichar gEarthlyBranchList[] = {
|
||||
0x5b50, 0x4e11, 0x5bc5, 0x536f, 0x8fb0, 0x5df3,
|
||||
0x5348, 0x672a, 0x7533, 0x9149, 0x620c, 0x4ea5
|
||||
};
|
||||
nsAutoString tmp(gEarthlyBranchList,
|
||||
sizeof(gEarthlyBranchList)/sizeof(PRUnichar));
|
||||
inst = new nsCharOrderIdFormater(new nsStringCharsList(tmp));
|
||||
} else if(mCID.Equals(kBoPoMoFoOrderIdCID)) {
|
||||
//
|
||||
// Note: Although Unicode standard encode 0x312A-0x312C as BoPoMoFo,
|
||||
// these three are origional designed for Mid China dialet
|
||||
// and have never been used for Maderine. Therefore, we
|
||||
// do not use them for order id.
|
||||
inst = new nsCharOrderIdFormater(new nsRangeCharsList(0x3105, 0x3129));
|
||||
} else if(mCID.Equals(kKatakanaOrderIdCID)) {
|
||||
// XXX fake list- need to verify with momoi about the real seq.
|
||||
static PRUnichar gKatakanaList[] = {
|
||||
0x3042, 0x3044, 0x3046, 0x3048, 0x304a
|
||||
};
|
||||
nsAutoString tmp(gKatakanaClassList, sizeof(gKatakanaList)/sizeof(PRUnichar));
|
||||
inst = new nsCharOrderIdFormater(new nsStringCharsList(tmp));
|
||||
} else if(mCID.Equals(kHiraganaOrderIdCID)) {
|
||||
// XXX fake list- need to verify with momoi about the real seq.
|
||||
static PRUnichar gHiraganaList[] = {
|
||||
0x30a2, 0x30a4, 0x30a6, 0x30a8, 0x30aa
|
||||
};
|
||||
nsAutoString tmp(gHiraganaList, sizeof(gHiraganaList)/sizeof(PRUnichar));
|
||||
inst = new nsCharOrderIdFormater(new nsStringCharsList(tmp));
|
||||
} else {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
|
||||
if(NULL == inst )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult res = inst->QueryInterface(aIID, aResult);
|
||||
if(NS_FAILED(res)) {
|
||||
delete inst;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
44
intl/unicharutil/src/nsCharsOrderIdFormater.h
Normal file
44
intl/unicharutil/src/nsCharsOrderIdFormater.h
Normal file
@ -0,0 +1,44 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsCharsOrderIdFormater_h__
|
||||
#define nsCharsOrderIdFormater_h__
|
||||
|
||||
|
||||
#include "nsIOrderIdFormater.h"
|
||||
#include "nsCharsList.h"
|
||||
|
||||
class nsCharsOrderIdFormater : public nsIOrderIdFormater {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
nsCharsOrderIdFormater( nsCharsList* aList);
|
||||
|
||||
virtual nsCharsOrderIdFormater();
|
||||
|
||||
|
||||
// Convert one Unicode character into upper case
|
||||
NS_IMETHOD ToString( PRUint32 aOrder, nsString& aResult) = 0;
|
||||
|
||||
private:
|
||||
|
||||
nsCharsList *mList;
|
||||
PRUint32 mBase;
|
||||
};
|
||||
|
||||
#endif /* nsCharsOrderIdFormater_h__ */
|
40
intl/unicharutil/src/nsRangeCharsList.cpp
Normal file
40
intl/unicharutil/src/nsRangeCharsList.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsRangeCharsList.h"
|
||||
|
||||
nsRangeCharsList::nsRangeCharsList(PRUnichar aStart, PRUnichar aEnd)
|
||||
{
|
||||
mStart = aStart;
|
||||
mEnd = aEnd;
|
||||
}
|
||||
nsRangeCharsList::~nsRangeCharsList()
|
||||
{
|
||||
}
|
||||
|
||||
PRUnichar nsRangeCharsList::Get( PRUint32 aIdx)
|
||||
{
|
||||
return mStart + aIdx;
|
||||
}
|
||||
|
||||
|
||||
PRUint32 nsRangeCharsList::Length()
|
||||
{
|
||||
return mEnd - mStart + 1;
|
||||
}
|
||||
|
39
intl/unicharutil/src/nsRangeCharsList.h
Normal file
39
intl/unicharutil/src/nsRangeCharsList.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsRangeCharsList_h__
|
||||
#define nsRangeCharsList_h__
|
||||
|
||||
|
||||
#include "nsCharsList.h"
|
||||
|
||||
class nsRangeCharsList : public nsCharsList {
|
||||
|
||||
public:
|
||||
nsRangeCharsList(PRUnichar aStart, PRUnichar aEnd);
|
||||
virtual ~nsRangeCharsList();
|
||||
|
||||
virtual PRUnichar Get( PRUint32 aIdx) ;
|
||||
|
||||
virtual PRUint32 Length() ;
|
||||
|
||||
private:
|
||||
PRUnichar mStart;
|
||||
PRUnichar mEnd;
|
||||
};
|
||||
|
||||
#endif /* nsRangeCharsList_h__ */
|
38
intl/unicharutil/src/nsStringCharsList.cpp
Normal file
38
intl/unicharutil/src/nsStringCharsList.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsStringCharsList.h"
|
||||
|
||||
nsStringCharsList::nsStringCharsList(nsString& aList)
|
||||
: mList(aList)
|
||||
{
|
||||
}
|
||||
|
||||
nsStringCharsList::~nsStringCharsList()
|
||||
{
|
||||
}
|
||||
|
||||
PRUnichar nsStringCharsList::Get( PRUint32 aIdx)
|
||||
{
|
||||
return (PRUnichar)mList(aIdx);
|
||||
}
|
||||
|
||||
PRUint32 nsStringCharsList::Length()
|
||||
{
|
||||
return mList.Length();
|
||||
}
|
40
intl/unicharutil/src/nsStringCharsList.h
Normal file
40
intl/unicharutil/src/nsStringCharsList.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsStringCharsList_h__
|
||||
#define nsStringCharsList_h__
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCharsList.h"
|
||||
|
||||
class nsStringCharsList : public nsCharsList {
|
||||
|
||||
public:
|
||||
nsStringCharsList(nsString& aList);
|
||||
virtual ~nsStringCharsList();
|
||||
|
||||
virtual PRUnichar Get( PRUint32 aIdx) ;
|
||||
|
||||
virtual PRUint32 Length() ;
|
||||
|
||||
private:
|
||||
nsString mList;
|
||||
};
|
||||
|
||||
#endif /* nsStringCharsList_h__ */
|
Loading…
Reference in New Issue
Block a user