From 95d921dff4142f8d5d704b1ad5953281feae5fc2 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Sat, 9 Jan 1999 01:09:39 +0000 Subject: [PATCH] modest improvements to string and deque --- base/src/nsDeque.cpp | 72 +++++++++++++++++++---------- base/src/nsDeque.h | 29 ++++++++---- base/src/nsString.cpp | 74 ++++++++++++++++++++++++++++++ base/src/nsString.h | 6 +++ string/obsolete/nsString.cpp | 74 ++++++++++++++++++++++++++++++ string/obsolete/nsString.h | 6 +++ xpcom/ds/nsDeque.cpp | 72 +++++++++++++++++++---------- xpcom/ds/nsDeque.h | 29 ++++++++---- xpcom/ds/nsString.cpp | 74 ++++++++++++++++++++++++++++++ xpcom/ds/nsString.h | 6 +++ xpcom/string/obsolete/nsString.cpp | 74 ++++++++++++++++++++++++++++++ xpcom/string/obsolete/nsString.h | 6 +++ 12 files changed, 454 insertions(+), 68 deletions(-) diff --git a/base/src/nsDeque.cpp b/base/src/nsDeque.cpp index dee188d45338..8be672a91e36 100644 --- a/base/src/nsDeque.cpp +++ b/base/src/nsDeque.cpp @@ -86,12 +86,12 @@ nsDeque& nsDeque::Erase() { /** - * This method adds an item to the end of the queue. + * This method adds an item to the end of the deque. * This operation has the potential to cause the * underlying buffer to resize. * * @update gess4/18/98 - * @param anItem: new item to be added to queue + * @param anItem: new item to be added to deque * @return nada */ nsDeque& nsDeque::Push(void* anItem) { @@ -122,6 +122,50 @@ nsDeque& nsDeque::Push(void* anItem) { } +/** + * This method adds an item to the front of the deque. + * This operation has the potential to cause the + * underlying buffer to resize. + * + * @update gess4/18/98 + * @param anItem: new item to be added to deque + * @return nada + */ +nsDeque& nsDeque::PushFront(void* anItem) { + if(mOrigin>0) { + mOrigin-=1; + mData[mOrigin]=anItem; + mSize++; + } + else { + Push(anItem); + mOrigin=mSize-1; + } + return *this; +} + +/** + * Remove and return the last item in the container. + * + * @update gess4/18/98 + * @param none + * @return ptr to last item in container + */ +void* nsDeque::Pop(void) { + void* result=0; + if(mSize>0) { + int offset=mOrigin+mSize-1; + if(offset>=mCapacity) + offset-=mCapacity; + result=mData[offset]; + mData[offset]=0; + mSize--; + if(0==mSize) + mOrigin=0; + } + return result; +} + /** * This method gets called you want to remove and return * the first member in the container. @@ -130,7 +174,7 @@ nsDeque& nsDeque::Push(void* anItem) { * @param nada * @return last item in container */ -void* nsDeque::Pop() { +void* nsDeque::PopFront() { void* result=0; if(mSize>0) { result=mData[mOrigin]; @@ -161,28 +205,6 @@ void* nsDeque::Peek() { return result; } -/** - * Remove and return the last item in the container. - * - * @update gess4/18/98 - * @param none - * @return ptr to last item in container - */ -void* nsDeque::PopBack(void) { - void* result=0; - if(mSize>0) { - int offset=mOrigin+mSize-1; - if(offset>=mCapacity) - offset-=mCapacity; - result=mData[offset]; - mData[offset]=0; - mSize--; - if(0==mSize) - mOrigin=0; - } - return result; -} - /** * Call this to retrieve the ith element from this container. * Keep in mind that accessing the underlying elements is diff --git a/base/src/nsDeque.h b/base/src/nsDeque.h index 7722783d149f..3f8269368b6a 100644 --- a/base/src/nsDeque.h +++ b/base/src/nsDeque.h @@ -93,6 +93,15 @@ friend class nsDequeIterator; * @return *this */ nsDeque& Push(void* anItem); + + /** + * Pushes new member onto the front of the deque + * + * @update gess4/18/98 + * @param ptr to object to store + * @return *this + */ + nsDeque& PushFront(void* anItem); /** * Remove and return the first item in the container. @@ -103,6 +112,16 @@ friend class nsDequeIterator; */ void* Pop(void); + /** + * Remove and return the first item in the container. + * + * @update gess4/18/98 + * @param none + * @return ptr to first item in container + */ + void* PopFront(void); + + /** * Return topmost item without removing it. * @@ -112,15 +131,7 @@ friend class nsDequeIterator; */ void* Peek(void); - /** - * Remove and return the last item in the container. - * - * @update gess4/18/98 - * @param none - * @return ptr to first item in container - */ - void* PopBack(void); - + /** * Remove all items from container without destroying them * diff --git a/base/src/nsString.cpp b/base/src/nsString.cpp index fcd8f1e89469..653044ea7433 100644 --- a/base/src/nsString.cpp +++ b/base/src/nsString.cpp @@ -39,6 +39,63 @@ PRUnichar kCommonEmptyBuffer[100]; //shared by all strings; NEVER WRITE HERE!! PRBool nsString::mSelfTested = PR_FALSE; + +#define NOT_USED 0xfffd + +static PRUint16 PA_HackTable[] = { + NOT_USED, + NOT_USED, + 0x201a, /* SINGLE LOW-9 QUOTATION MARK */ + 0x0192, /* LATIN SMALL LETTER F WITH HOOK */ + 0x201e, /* DOUBLE LOW-9 QUOTATION MARK */ + 0x2026, /* HORIZONTAL ELLIPSIS */ + 0x2020, /* DAGGER */ + 0x2021, /* DOUBLE DAGGER */ + 0x02c6, /* MODIFIER LETTER CIRCUMFLEX ACCENT */ + 0x2030, /* PER MILLE SIGN */ + 0x0160, /* LATIN CAPITAL LETTER S WITH CARON */ + 0x2039, /* SINGLE LEFT-POINTING ANGLE QUOTATION MARK */ + 0x0152, /* LATIN CAPITAL LIGATURE OE */ + NOT_USED, + NOT_USED, + NOT_USED, + + NOT_USED, + 0x2018, /* LEFT SINGLE QUOTATION MARK */ + 0x2019, /* RIGHT SINGLE QUOTATION MARK */ + 0x201c, /* LEFT DOUBLE QUOTATION MARK */ + 0x201d, /* RIGHT DOUBLE QUOTATION MARK */ + 0x2022, /* BULLET */ + 0x2013, /* EN DASH */ + 0x2014, /* EM DASH */ + 0x02dc, /* SMALL TILDE */ + 0x2122, /* TRADE MARK SIGN */ + 0x0161, /* LATIN SMALL LETTER S WITH CARON */ + 0x203a, /* SINGLE RIGHT-POINTING ANGLE QUOTATION MARK */ + 0x0153, /* LATIN SMALL LIGATURE OE */ + NOT_USED, + NOT_USED, + 0x0178 /* LATIN CAPITAL LETTER Y WITH DIAERESIS */ +}; + +static PRUnichar gToUCS2[256]; + +class CTableConstructor { +public: + CTableConstructor(){ + PRUnichar* cp = gToUCS2; + PRInt32 i; + for (i = 0; i < 256; i++) { + *cp++ = PRUnichar(i); + } + cp = gToUCS2; + for (i = 0; i < 32; i++) { + cp[0x80 + i] = PA_HackTable[i]; + } + } +}; +static CTableConstructor gTableConstructor; + /*********************************************************************** IMPLEMENTATION NOTES: @@ -402,6 +459,23 @@ void nsString::ToUpperCase() } } +/** + * Converts all chars in given string to UCS2 + */ +void nsString::ToUCS2(PRInt32 aStartOffset){ + if(aStartOffset0) { + mOrigin-=1; + mData[mOrigin]=anItem; + mSize++; + } + else { + Push(anItem); + mOrigin=mSize-1; + } + return *this; +} + +/** + * Remove and return the last item in the container. + * + * @update gess4/18/98 + * @param none + * @return ptr to last item in container + */ +void* nsDeque::Pop(void) { + void* result=0; + if(mSize>0) { + int offset=mOrigin+mSize-1; + if(offset>=mCapacity) + offset-=mCapacity; + result=mData[offset]; + mData[offset]=0; + mSize--; + if(0==mSize) + mOrigin=0; + } + return result; +} + /** * This method gets called you want to remove and return * the first member in the container. @@ -130,7 +174,7 @@ nsDeque& nsDeque::Push(void* anItem) { * @param nada * @return last item in container */ -void* nsDeque::Pop() { +void* nsDeque::PopFront() { void* result=0; if(mSize>0) { result=mData[mOrigin]; @@ -161,28 +205,6 @@ void* nsDeque::Peek() { return result; } -/** - * Remove and return the last item in the container. - * - * @update gess4/18/98 - * @param none - * @return ptr to last item in container - */ -void* nsDeque::PopBack(void) { - void* result=0; - if(mSize>0) { - int offset=mOrigin+mSize-1; - if(offset>=mCapacity) - offset-=mCapacity; - result=mData[offset]; - mData[offset]=0; - mSize--; - if(0==mSize) - mOrigin=0; - } - return result; -} - /** * Call this to retrieve the ith element from this container. * Keep in mind that accessing the underlying elements is diff --git a/xpcom/ds/nsDeque.h b/xpcom/ds/nsDeque.h index 7722783d149f..3f8269368b6a 100644 --- a/xpcom/ds/nsDeque.h +++ b/xpcom/ds/nsDeque.h @@ -93,6 +93,15 @@ friend class nsDequeIterator; * @return *this */ nsDeque& Push(void* anItem); + + /** + * Pushes new member onto the front of the deque + * + * @update gess4/18/98 + * @param ptr to object to store + * @return *this + */ + nsDeque& PushFront(void* anItem); /** * Remove and return the first item in the container. @@ -103,6 +112,16 @@ friend class nsDequeIterator; */ void* Pop(void); + /** + * Remove and return the first item in the container. + * + * @update gess4/18/98 + * @param none + * @return ptr to first item in container + */ + void* PopFront(void); + + /** * Return topmost item without removing it. * @@ -112,15 +131,7 @@ friend class nsDequeIterator; */ void* Peek(void); - /** - * Remove and return the last item in the container. - * - * @update gess4/18/98 - * @param none - * @return ptr to first item in container - */ - void* PopBack(void); - + /** * Remove all items from container without destroying them * diff --git a/xpcom/ds/nsString.cpp b/xpcom/ds/nsString.cpp index fcd8f1e89469..653044ea7433 100644 --- a/xpcom/ds/nsString.cpp +++ b/xpcom/ds/nsString.cpp @@ -39,6 +39,63 @@ PRUnichar kCommonEmptyBuffer[100]; //shared by all strings; NEVER WRITE HERE!! PRBool nsString::mSelfTested = PR_FALSE; + +#define NOT_USED 0xfffd + +static PRUint16 PA_HackTable[] = { + NOT_USED, + NOT_USED, + 0x201a, /* SINGLE LOW-9 QUOTATION MARK */ + 0x0192, /* LATIN SMALL LETTER F WITH HOOK */ + 0x201e, /* DOUBLE LOW-9 QUOTATION MARK */ + 0x2026, /* HORIZONTAL ELLIPSIS */ + 0x2020, /* DAGGER */ + 0x2021, /* DOUBLE DAGGER */ + 0x02c6, /* MODIFIER LETTER CIRCUMFLEX ACCENT */ + 0x2030, /* PER MILLE SIGN */ + 0x0160, /* LATIN CAPITAL LETTER S WITH CARON */ + 0x2039, /* SINGLE LEFT-POINTING ANGLE QUOTATION MARK */ + 0x0152, /* LATIN CAPITAL LIGATURE OE */ + NOT_USED, + NOT_USED, + NOT_USED, + + NOT_USED, + 0x2018, /* LEFT SINGLE QUOTATION MARK */ + 0x2019, /* RIGHT SINGLE QUOTATION MARK */ + 0x201c, /* LEFT DOUBLE QUOTATION MARK */ + 0x201d, /* RIGHT DOUBLE QUOTATION MARK */ + 0x2022, /* BULLET */ + 0x2013, /* EN DASH */ + 0x2014, /* EM DASH */ + 0x02dc, /* SMALL TILDE */ + 0x2122, /* TRADE MARK SIGN */ + 0x0161, /* LATIN SMALL LETTER S WITH CARON */ + 0x203a, /* SINGLE RIGHT-POINTING ANGLE QUOTATION MARK */ + 0x0153, /* LATIN SMALL LIGATURE OE */ + NOT_USED, + NOT_USED, + 0x0178 /* LATIN CAPITAL LETTER Y WITH DIAERESIS */ +}; + +static PRUnichar gToUCS2[256]; + +class CTableConstructor { +public: + CTableConstructor(){ + PRUnichar* cp = gToUCS2; + PRInt32 i; + for (i = 0; i < 256; i++) { + *cp++ = PRUnichar(i); + } + cp = gToUCS2; + for (i = 0; i < 32; i++) { + cp[0x80 + i] = PA_HackTable[i]; + } + } +}; +static CTableConstructor gTableConstructor; + /*********************************************************************** IMPLEMENTATION NOTES: @@ -402,6 +459,23 @@ void nsString::ToUpperCase() } } +/** + * Converts all chars in given string to UCS2 + */ +void nsString::ToUCS2(PRInt32 aStartOffset){ + if(aStartOffset