1999-03-22 12:54:46 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-03-22 12:54:46 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-12-01 02:36:32 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************************
|
|
|
|
MODULE NOTES:
|
|
|
|
|
|
|
|
This file contains the workhorse copy and shift functions used in nsStrStruct.
|
|
|
|
Ultimately, I plan to make the function pointers in this system available for
|
|
|
|
use by external modules. They'll be able to install their own "handlers".
|
|
|
|
Not so, today though.
|
|
|
|
|
|
|
|
*******************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _BUFFERROUTINES_H
|
|
|
|
#define _BUFFERROUTINES_H
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
#include "nsUnicharUtilCIID.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsICaseConversion.h"
|
|
|
|
#endif
|
|
|
|
|
1999-06-03 14:49:14 +04:00
|
|
|
#define KSHIFTLEFT (0)
|
|
|
|
#define KSHIFTRIGHT (1)
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
inline PRUnichar GetUnicharAt(const char* aString,PRUint32 anIndex) {
|
|
|
|
return ((PRUnichar*)aString)[anIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRUnichar GetCharAt(const char* aString,PRUint32 anIndex) {
|
|
|
|
return (PRUnichar)aString[anIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This set of methods is used to shift the contents of a char buffer.
|
|
|
|
// The functions are differentiated by shift direction and the underlying charsize.
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method shifts single byte characters left by a given amount from an given offset.
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aDest is a ptr to a cstring where left-shift is to be performed
|
|
|
|
* @param aLength is the known length of aDest
|
|
|
|
* @param anOffset is the index into aDest where shifting shall begin
|
|
|
|
* @param aCount is the number of chars to be "cut"
|
|
|
|
*/
|
|
|
|
void ShiftCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
1999-09-20 09:10:32 +04:00
|
|
|
char* dst = aDest+anOffset;
|
|
|
|
char* src = aDest+anOffset+aCount;
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-09-20 10:11:36 +04:00
|
|
|
memmove(dst,src,aLength-(aCount+anOffset));
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method shifts single byte characters right by a given amount from an given offset.
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aDest is a ptr to a cstring where the shift is to be performed
|
|
|
|
* @param aLength is the known length of aDest
|
|
|
|
* @param anOffset is the index into aDest where shifting shall begin
|
|
|
|
* @param aCount is the number of chars to be "inserted"
|
|
|
|
*/
|
|
|
|
void ShiftCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
1999-09-18 03:46:55 +04:00
|
|
|
char* src = aDest+anOffset;
|
|
|
|
char* dst = aDest+anOffset+aCount;
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-09-18 03:46:55 +04:00
|
|
|
memmove(dst,src,aLength-anOffset);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method shifts unicode characters by a given amount from an given offset.
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aDest is a ptr to a cstring where the shift is to be performed
|
|
|
|
* @param aLength is the known length of aDest
|
|
|
|
* @param anOffset is the index into aDest where shifting shall begin
|
|
|
|
* @param aCount is the number of chars to be "cut"
|
|
|
|
*/
|
|
|
|
void ShiftDoubleCharsLeft(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
1999-09-18 05:45:19 +04:00
|
|
|
PRUnichar* root=(PRUnichar*)aDest;
|
|
|
|
PRUnichar* dst = root+anOffset;
|
|
|
|
PRUnichar* src = root+anOffset+aCount;
|
|
|
|
|
1999-09-20 10:11:36 +04:00
|
|
|
memmove(dst,src,(aLength-(aCount+anOffset))*sizeof(PRUnichar));
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method shifts unicode characters by a given amount from an given offset.
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aDest is a ptr to a cstring where the shift is to be performed
|
|
|
|
* @param aLength is the known length of aDest
|
|
|
|
* @param anOffset is the index into aDest where shifting shall begin
|
|
|
|
* @param aCount is the number of chars to be "inserted"
|
|
|
|
*/
|
|
|
|
void ShiftDoubleCharsRight(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount) {
|
1999-09-18 03:46:55 +04:00
|
|
|
PRUnichar* root=(PRUnichar*)aDest;
|
|
|
|
PRUnichar* src = root+anOffset;
|
|
|
|
PRUnichar* dst = root+anOffset+aCount;
|
|
|
|
|
|
|
|
memmove(dst,src,sizeof(PRUnichar)*(aLength-anOffset));
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (*ShiftChars)(char* aDest,PRUint32 aLength,PRUint32 anOffset,PRUint32 aCount);
|
|
|
|
ShiftChars gShiftChars[2][2]= {
|
|
|
|
{&ShiftCharsLeft,&ShiftCharsRight},
|
|
|
|
{&ShiftDoubleCharsLeft,&ShiftDoubleCharsRight}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This set of methods is used to copy one buffer onto another.
|
|
|
|
// The functions are differentiated by the size of source and dest character sizes.
|
|
|
|
// WARNING: Your destination buffer MUST be big enough to hold all the source bytes.
|
|
|
|
// We don't validate these ranges here (this should be done in higher level routines).
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Going 1 to 1 is easy, since we assume ascii. No conversions are necessary.
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aDest is the destination buffer
|
|
|
|
* @param aDestOffset is the pos to start copy to in the dest buffer
|
|
|
|
* @param aSource is the source buffer
|
|
|
|
* @param anOffset is the offset to start copying from in the source buffer
|
|
|
|
* @param aCount is the (max) number of chars to copy
|
|
|
|
*/
|
|
|
|
void CopyChars1To1(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
|
|
|
|
1999-09-18 03:46:55 +04:00
|
|
|
char* dst = aDest+anDestOffset;
|
|
|
|
char* src = (char*)aSource+anOffset;
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-09-18 03:46:55 +04:00
|
|
|
memcpy(dst,src,aCount);
|
1999-05-27 14:28:50 +04:00
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Going 1 to 2 requires a conversion from ascii to unicode. This can be expensive.
|
|
|
|
* @param aDest is the destination buffer
|
|
|
|
* @param aDestOffset is the pos to start copy to in the dest buffer
|
|
|
|
* @param aSource is the source buffer
|
|
|
|
* @param anOffset is the offset to start copying from in the source buffer
|
|
|
|
* @param aCount is the (max) number of chars to copy
|
|
|
|
*/
|
|
|
|
void CopyChars1To2(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
|
|
|
|
|
|
|
PRUnichar* theDest=(PRUnichar*)aDest;
|
|
|
|
PRUnichar* to = theDest+anDestOffset;
|
1999-06-08 04:28:47 +04:00
|
|
|
const unsigned char* first= (const unsigned char*)aSource+anOffset;
|
|
|
|
const unsigned char* last = first+aCount;
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
//now loop over characters, shifting them left...
|
|
|
|
while(first<last) {
|
1999-06-03 22:45:39 +04:00
|
|
|
*to=(PRUnichar)(*first);
|
1999-03-22 12:54:46 +03:00
|
|
|
to++;
|
|
|
|
first++;
|
|
|
|
}
|
|
|
|
}
|
1999-05-27 14:28:50 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Going 2 to 1 requires a conversion from unicode down to ascii. This can be lossy.
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aDest is the destination buffer
|
|
|
|
* @param aDestOffset is the pos to start copy to in the dest buffer
|
|
|
|
* @param aSource is the source buffer
|
|
|
|
* @param anOffset is the offset to start copying from in the source buffer
|
|
|
|
* @param aCount is the (max) number of chars to copy
|
|
|
|
*/
|
|
|
|
void CopyChars2To1(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
|
|
|
char* to = aDest+anDestOffset;
|
|
|
|
PRUnichar* theSource=(PRUnichar*)aSource;
|
|
|
|
const PRUnichar* first= theSource+anOffset;
|
|
|
|
const PRUnichar* last = first+aCount;
|
|
|
|
|
|
|
|
//now loop over characters, shifting them left...
|
|
|
|
while(first<last) {
|
1999-06-03 14:49:14 +04:00
|
|
|
if(*first<256)
|
1999-03-22 12:54:46 +03:00
|
|
|
*to=(char)*first;
|
|
|
|
else *to='.';
|
|
|
|
to++;
|
|
|
|
first++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Going 2 to 2 is fast and efficient.
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aDest is the destination buffer
|
|
|
|
* @param aDestOffset is the pos to start copy to in the dest buffer
|
|
|
|
* @param aSource is the source buffer
|
|
|
|
* @param anOffset is the offset to start copying from in the source buffer
|
|
|
|
* @param aCount is the (max) number of chars to copy
|
|
|
|
*/
|
|
|
|
void CopyChars2To2(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount) {
|
|
|
|
PRUnichar* theDest=(PRUnichar*)aDest;
|
|
|
|
PRUnichar* to = theDest+anDestOffset;
|
|
|
|
PRUnichar* theSource=(PRUnichar*)aSource;
|
|
|
|
PRUnichar* from= theSource+anOffset;
|
|
|
|
|
1999-09-18 03:46:55 +04:00
|
|
|
memcpy((void*)to,(void*)from,aCount*sizeof(PRUnichar));
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (*CopyChars)(char* aDest,PRInt32 anDestOffset,const char* aSource,PRUint32 anOffset,PRUint32 aCount);
|
|
|
|
|
|
|
|
CopyChars gCopyChars[2][2]={
|
|
|
|
{&CopyChars1To1,&CopyChars1To2},
|
|
|
|
{&CopyChars2To1,&CopyChars2To2}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This set of methods is used to search a buffer looking for a char.
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This methods cans the given buffer for the given char
|
|
|
|
*
|
2000-02-18 10:47:47 +03:00
|
|
|
* @update gess 02/17/00
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aDest is the buffer to be searched
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aDestLength is the size (in char-units, not bytes) of the buffer
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param anOffset is the start pos to begin searching
|
|
|
|
* @param aChar is the target character we're looking for
|
|
|
|
* @param aIgnorecase tells us whether to use a case sensitive search
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return index of pos if found, else -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
inline PRInt32 FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
|
|
|
|
|
|
|
|
if(anOffset<0)
|
|
|
|
anOffset=0;
|
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount = (PRInt32)aDestLength;
|
|
|
|
|
2000-02-18 10:47:47 +03:00
|
|
|
if((aChar<256) && (0<aDestLength) && ((PRUint32)anOffset<aDestLength)) {
|
|
|
|
|
|
|
|
//We'll only search if the given aChar is within the normal ascii a range,
|
|
|
|
//(Since this string is definitely within the ascii range).
|
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
if(0<aCount) {
|
|
|
|
|
|
|
|
const char* left= aDest+anOffset;
|
|
|
|
const char* last= left+aCount;
|
|
|
|
const char* max = aDest+aDestLength;
|
|
|
|
const char* end = (last<max) ? last : max;
|
|
|
|
|
|
|
|
if(aIgnoreCase) {
|
|
|
|
|
|
|
|
char theChar=(char)nsCRT::ToUpper(aChar);
|
|
|
|
while(left<end){
|
|
|
|
if(nsCRT::ToUpper(*left)==theChar)
|
|
|
|
return left-aDest;
|
|
|
|
++left;
|
|
|
|
}
|
1999-12-03 03:30:29 +03:00
|
|
|
}
|
2000-02-11 15:11:03 +03:00
|
|
|
else {
|
1999-09-30 08:03:49 +04:00
|
|
|
|
2000-02-13 20:45:01 +03:00
|
|
|
PRInt32 theMax = end-left;
|
|
|
|
if(0<theMax) {
|
|
|
|
char theChar=(char)aChar;
|
|
|
|
const char* result=(const char*)memchr(left, theChar, theMax);
|
|
|
|
if(result) {
|
|
|
|
return result-aDest;
|
|
|
|
}
|
2000-02-11 15:11:03 +03:00
|
|
|
}
|
1999-12-03 03:30:29 +03:00
|
|
|
}
|
1999-07-25 21:21:34 +04:00
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
2000-02-11 15:11:03 +03:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
* This methods cans the given buffer for the given char
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param aDest is the buffer to be searched
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aDestLength is the size (in char-units, not bytes) of the buffer
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param anOffset is the start pos to begin searching
|
|
|
|
* @param aChar is the target character we're looking for
|
|
|
|
* @param aIgnorecase tells us whether to use a case sensitive search
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return index of pos if found, else -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
inline PRInt32 FindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
|
|
|
|
|
|
|
|
if(anOffset<0)
|
|
|
|
anOffset=0;
|
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount = (PRInt32)aDestLength;
|
|
|
|
|
|
|
|
if((0<aDestLength) && ((PRUint32)anOffset<aDestLength)) {
|
|
|
|
|
|
|
|
if(0<aCount) {
|
|
|
|
|
|
|
|
const PRUnichar* root = (PRUnichar*)aDest;
|
|
|
|
const PRUnichar* left = root+anOffset;
|
|
|
|
const PRUnichar* last = left+aCount;
|
|
|
|
const PRUnichar* max = root+aDestLength;
|
|
|
|
const PRUnichar* end = (last<max) ? last : max;
|
|
|
|
|
|
|
|
if(aIgnoreCase) {
|
|
|
|
PRUnichar theChar=nsCRT::ToUpper(aChar);
|
|
|
|
while(left<end){
|
|
|
|
if(nsCRT::ToUpper(*left)==theChar)
|
|
|
|
return left-root;
|
|
|
|
++left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while(left<end){
|
|
|
|
if(*left==aChar)
|
|
|
|
return (left-root);
|
|
|
|
++left;
|
|
|
|
}
|
|
|
|
}
|
1999-07-25 21:21:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This methods cans the given buffer (in reverse) for the given char
|
|
|
|
*
|
2000-02-18 10:47:47 +03:00
|
|
|
* @update gess 02/17/00
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aDest is the buffer to be searched
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aDestLength is the size (in char-units, not bytes) of the buffer
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param anOffset is the start pos to begin searching
|
|
|
|
* @param aChar is the target character we're looking for
|
|
|
|
* @param aIgnorecase tells us whether to use a case sensitive search
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return index of pos if found, else -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
|
|
|
|
inline PRInt32 RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
|
|
|
|
|
|
|
|
if(anOffset<0)
|
|
|
|
anOffset=(PRInt32)aDestLength-1;
|
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount = aDestLength;
|
|
|
|
|
2000-02-18 10:47:47 +03:00
|
|
|
if((aChar<256) && (0<aDestLength) && ((PRUint32)anOffset<aDestLength)) {
|
|
|
|
|
|
|
|
//We'll only search if the given aChar is within the normal ascii a range,
|
|
|
|
//(Since this string is definitely within the ascii range).
|
2000-02-11 15:11:03 +03:00
|
|
|
|
|
|
|
if(0<aCount) {
|
|
|
|
|
|
|
|
const char* rightmost = aDest+anOffset;
|
|
|
|
const char* min = rightmost-aCount+1;
|
|
|
|
const char* leftmost = (min<aDest) ? aDest: min;
|
|
|
|
|
|
|
|
if(aIgnoreCase) {
|
|
|
|
|
|
|
|
char theChar=(char)nsCRT::ToUpper(aChar);
|
|
|
|
while(leftmost<rightmost){
|
|
|
|
if(nsCRT::ToUpper(*rightmost)==theChar)
|
|
|
|
return rightmost-aDest;
|
|
|
|
--rightmost;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
char theChar=(char)aChar;
|
|
|
|
while(leftmost<=rightmost){
|
|
|
|
if((*rightmost)==theChar)
|
|
|
|
return rightmost-aDest;
|
|
|
|
--rightmost;
|
|
|
|
}
|
|
|
|
}
|
1999-07-25 21:21:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This methods cans the given buffer for the given char
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param aDest is the buffer to be searched
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aDestLength is the size (in char-units, not bytes) of the buffer
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param anOffset is the start pos to begin searching
|
|
|
|
* @param aChar is the target character we're looking for
|
|
|
|
* @param aIgnorecase tells us whether to use a case sensitive search
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aCount tells us how many characters to iterate through (which may be different than aLength); -1 means use full length.
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return index of pos if found, else -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
inline PRInt32 RFindChar2(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount) {
|
1999-07-25 21:21:34 +04:00
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
if(anOffset<0)
|
|
|
|
anOffset=(PRInt32)aDestLength-1;
|
1999-07-25 21:21:34 +04:00
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
if(aCount<0)
|
|
|
|
aCount = aDestLength;
|
|
|
|
|
|
|
|
if((0<aDestLength) && ((PRUint32)anOffset<aDestLength)) {
|
|
|
|
|
|
|
|
if(0<aCount) {
|
|
|
|
|
|
|
|
const PRUnichar* root = (PRUnichar*)aDest;
|
|
|
|
const PRUnichar* rightmost = root+anOffset;
|
|
|
|
const PRUnichar* min = rightmost-aCount+1;
|
|
|
|
const PRUnichar* leftmost = (min<root) ? root: min;
|
|
|
|
|
|
|
|
if(aIgnoreCase) {
|
|
|
|
|
|
|
|
PRUnichar theChar=nsCRT::ToUpper(aChar);
|
|
|
|
while(leftmost<rightmost){
|
|
|
|
if(nsCRT::ToUpper(*rightmost)==theChar)
|
|
|
|
return rightmost-root;
|
|
|
|
--rightmost;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
while(leftmost<=rightmost){
|
|
|
|
if((*rightmost)==aChar)
|
|
|
|
return rightmost-root;
|
|
|
|
--rightmost;
|
|
|
|
}
|
|
|
|
}
|
1999-07-25 21:21:34 +04:00
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
1999-07-25 21:21:34 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
typedef PRInt32 (*FindChars)(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnichar aChar,PRBool aIgnoreCase,PRInt32 aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
FindChars gFindChars[]={&FindChar1,&FindChar2};
|
|
|
|
FindChars gRFindChars[]={&RFindChar1,&RFindChar2};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This set of methods is used to compare one buffer onto another.
|
|
|
|
// The functions are differentiated by the size of source and dest character sizes.
|
|
|
|
// WARNING: Your destination buffer MUST be big enough to hold all the source bytes.
|
|
|
|
// We don't validate these ranges here (this should be done in higher level routines).
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method compares the data in one buffer with another
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aStr1 is the first buffer to be compared
|
|
|
|
* @param aStr2 is the 2nd buffer to be compared
|
|
|
|
* @param aCount is the number of chars to compare
|
|
|
|
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
|
|
|
* @return -1,0,1 depending on <,==,>
|
|
|
|
*/
|
|
|
|
PRInt32 Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
|
|
|
PRInt32 result=0;
|
|
|
|
if(aIgnoreCase)
|
|
|
|
result=nsCRT::strncasecmp(aStr1,aStr2,aCount);
|
1999-11-14 09:22:52 +03:00
|
|
|
else result=memcmp(aStr1,aStr2,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method compares the data in one buffer with another
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aStr1 is the first buffer to be compared
|
|
|
|
* @param aStr2 is the 2nd buffer to be compared
|
|
|
|
* @param aCount is the number of chars to compare
|
|
|
|
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
|
|
|
* @return -1,0,1 depending on <,==,>
|
|
|
|
*/
|
|
|
|
PRInt32 Compare2To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
|
|
|
PRInt32 result=0;
|
|
|
|
if(aIgnoreCase)
|
|
|
|
result=nsCRT::strncasecmp((PRUnichar*)aStr1,(PRUnichar*)aStr2,aCount);
|
|
|
|
else result=nsCRT::strncmp((PRUnichar*)aStr1,(PRUnichar*)aStr2,aCount);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method compares the data in one buffer with another
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aStr1 is the first buffer to be compared
|
|
|
|
* @param aStr2 is the 2nd buffer to be compared
|
|
|
|
* @param aCount is the number of chars to compare
|
|
|
|
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
|
|
|
* @return -1,0,1 depending on <,==,>
|
|
|
|
*/
|
|
|
|
PRInt32 Compare2To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
|
|
|
PRInt32 result;
|
|
|
|
if(aIgnoreCase)
|
|
|
|
result=nsCRT::strncasecmp((PRUnichar*)aStr1,aStr2,aCount);
|
|
|
|
else result=nsCRT::strncmp((PRUnichar*)aStr1,aStr2,aCount);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method compares the data in one buffer with another
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aStr1 is the first buffer to be compared
|
|
|
|
* @param aStr2 is the 2nd buffer to be compared
|
|
|
|
* @param aCount is the number of chars to compare
|
|
|
|
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
|
|
|
* @return -1,0,1 depending on <,==,>
|
|
|
|
*/
|
|
|
|
PRInt32 Compare1To2(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
|
|
|
|
PRInt32 result;
|
|
|
|
if(aIgnoreCase)
|
|
|
|
result=nsCRT::strncasecmp((PRUnichar*)aStr2,aStr1,aCount)*-1;
|
1999-06-03 14:49:14 +04:00
|
|
|
else result=nsCRT::strncmp((PRUnichar*)aStr2,aStr1,aCount)*-1;
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef PRInt32 (*CompareChars)(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase);
|
|
|
|
CompareChars gCompare[2][2]={
|
|
|
|
{&Compare1To1,&Compare1To2},
|
|
|
|
{&Compare2To1,&Compare2To2},
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This set of methods is used to convert the case of strings...
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method performs a case conversion the data in the given buffer
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aString is the buffer to be case shifted
|
|
|
|
* @param aCount is the number of chars to compare
|
|
|
|
* @param aToUpper tells us whether to convert to upper or lower
|
|
|
|
* @return 0
|
|
|
|
*/
|
|
|
|
PRInt32 ConvertCase1(char* aString,PRUint32 aCount,PRBool aToUpper){
|
|
|
|
PRInt32 result=0;
|
|
|
|
|
|
|
|
typedef char chartype;
|
|
|
|
chartype* cp = (chartype*)aString;
|
|
|
|
chartype* end = cp + aCount-1;
|
|
|
|
while (cp <= end) {
|
|
|
|
chartype ch = *cp;
|
|
|
|
if(aToUpper) {
|
|
|
|
if ((ch >= 'a') && (ch <= 'z')) {
|
|
|
|
*cp = 'A' + (ch - 'a');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((ch >= 'A') && (ch <= 'Z')) {
|
|
|
|
*cp = 'a' + (ch - 'A');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
class HandleCaseConversionShutdown3 : public nsIShutdownListener {
|
|
|
|
public :
|
|
|
|
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
|
|
|
HandleCaseConversionShutdown3(void) { NS_INIT_REFCNT(); }
|
|
|
|
virtual ~HandleCaseConversionShutdown3(void) {}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
};
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
|
|
|
static nsICaseConversion * gCaseConv = 0;
|
|
|
|
|
1999-12-01 02:36:32 +03:00
|
|
|
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown3, NS_GET_IID(nsIShutdownListener));
|
1999-05-06 09:13:08 +04:00
|
|
|
|
|
|
|
nsresult HandleCaseConversionShutdown3::OnShutdown(const nsCID& cid, nsISupports* service) {
|
|
|
|
if (cid.Equals(kUnicharUtilCID)) {
|
|
|
|
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
1999-09-30 08:03:49 +04:00
|
|
|
if(gCaseConv){
|
|
|
|
gCaseConv->Release();
|
|
|
|
gCaseConv = 0;
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
}
|
1999-09-30 08:03:49 +04:00
|
|
|
return NS_OK;
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CCaseConversionServiceInitializer {
|
|
|
|
public:
|
|
|
|
CCaseConversionServiceInitializer(){
|
2000-01-28 17:41:04 +03:00
|
|
|
HandleCaseConversionShutdown3* listener =
|
|
|
|
new HandleCaseConversionShutdown3();
|
|
|
|
if(listener){
|
|
|
|
nsServiceManager::GetService(kUnicharUtilCID, NS_GET_IID(nsICaseConversion),(nsISupports**) &gCaseConv, listener);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
* This method performs a case conversion the data in the given buffer
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aString is the buffer to be case shifted
|
|
|
|
* @param aCount is the number of chars to compare
|
|
|
|
* @param aToUpper tells us whether to convert to upper or lower
|
|
|
|
* @return 0
|
|
|
|
*/
|
|
|
|
PRInt32 ConvertCase2(char* aString,PRUint32 aCount,PRBool aToUpper){
|
1999-05-06 09:13:08 +04:00
|
|
|
PRUnichar* cp = (PRUnichar*)aString;
|
|
|
|
PRUnichar* end = cp + aCount-1;
|
1999-03-22 12:54:46 +03:00
|
|
|
PRInt32 result=0;
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
static CCaseConversionServiceInitializer gCaseConversionServiceInitializer;
|
|
|
|
|
|
|
|
// I18N code begin
|
|
|
|
if(gCaseConv) {
|
|
|
|
nsresult err=(aToUpper) ? gCaseConv->ToUpper(cp, cp, aCount) : gCaseConv->ToLower(cp, cp, aCount);
|
|
|
|
if(NS_SUCCEEDED(err))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// I18N code end
|
|
|
|
#endif
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
while (cp <= end) {
|
1999-05-06 09:13:08 +04:00
|
|
|
PRUnichar ch = *cp;
|
1999-03-22 12:54:46 +03:00
|
|
|
if(aToUpper) {
|
|
|
|
if ((ch >= 'a') && (ch <= 'z')) {
|
|
|
|
*cp = 'A' + (ch - 'a');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((ch >= 'A') && (ch <= 'Z')) {
|
|
|
|
*cp = 'a' + (ch - 'A');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef PRInt32 (*CaseConverters)(char*,PRUint32,PRBool);
|
|
|
|
CaseConverters gCaseConverters[]={&ConvertCase1,&ConvertCase2};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This set of methods is used compress char sequences in a buffer...
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method compresses duplicate runs of a given char from the given buffer
|
|
|
|
*
|
2000-02-11 15:11:03 +03:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString is the buffer to be manipulated
|
|
|
|
* @param aLength is the length of the buffer
|
|
|
|
* @param aSet tells us which chars to compress from given buffer
|
|
|
|
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
|
|
|
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
|
|
|
* @return the new length of the given buffer
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-11-14 09:22:52 +03:00
|
|
|
char* from = aString;
|
|
|
|
char* end = aString + aLength-1;
|
|
|
|
char* to = from;
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
//this code converts /n, /t, /r into normal space ' ';
|
|
|
|
//it also compresses runs of whitespace down to a single char...
|
1999-09-11 04:10:36 +04:00
|
|
|
if(aSet && aString && (0 < aLength)){
|
1999-03-22 12:54:46 +03:00
|
|
|
PRUint32 aSetLen=strlen(aSet);
|
|
|
|
while (from <= end) {
|
1999-11-14 09:22:52 +03:00
|
|
|
char theChar = *from++;
|
2000-02-11 15:11:03 +03:00
|
|
|
if(kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){
|
1999-07-30 06:22:37 +04:00
|
|
|
*to++=theChar;
|
1999-03-22 12:54:46 +03:00
|
|
|
while (from <= end) {
|
1999-07-17 11:26:16 +04:00
|
|
|
theChar = *from++;
|
2000-02-11 15:11:03 +03:00
|
|
|
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){
|
1999-07-17 11:26:16 +04:00
|
|
|
*to++ = theChar;
|
1999-03-22 12:54:46 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
1999-07-17 11:26:16 +04:00
|
|
|
*to++ = theChar;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*to = 0;
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
return to - (char*)aString;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method compresses duplicate runs of a given char from the given buffer
|
|
|
|
*
|
2000-02-11 15:11:03 +03:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString is the buffer to be manipulated
|
|
|
|
* @param aLength is the length of the buffer
|
|
|
|
* @param aSet tells us which chars to compress from given buffer
|
|
|
|
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
|
|
|
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
|
|
|
* @return the new length of the given buffer
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 CompressChars2(char* aString,PRUint32 aLength,const char* aSet){
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-11-14 09:22:52 +03:00
|
|
|
PRUnichar* from = (PRUnichar*)aString;
|
|
|
|
PRUnichar* end = from + aLength-1;
|
|
|
|
PRUnichar* to = from;
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
//this code converts /n, /t, /r into normal space ' ';
|
|
|
|
//it also compresses runs of whitespace down to a single char...
|
1999-09-11 04:10:36 +04:00
|
|
|
if(aSet && aString && (0 < aLength)){
|
1999-03-22 12:54:46 +03:00
|
|
|
PRUint32 aSetLen=strlen(aSet);
|
|
|
|
while (from <= end) {
|
1999-11-14 09:22:52 +03:00
|
|
|
PRUnichar theChar = *from++;
|
2000-02-11 15:11:03 +03:00
|
|
|
if((255<theChar) || (kNotFound!=FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){
|
1999-07-30 06:22:37 +04:00
|
|
|
*to++=theChar;
|
1999-03-22 12:54:46 +03:00
|
|
|
while (from <= end) {
|
1999-07-17 11:26:16 +04:00
|
|
|
theChar = *from++;
|
2000-02-11 15:11:03 +03:00
|
|
|
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){
|
1999-07-17 11:26:16 +04:00
|
|
|
*to++ = theChar;
|
1999-03-22 12:54:46 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-02-11 15:11:03 +03:00
|
|
|
} else {
|
1999-07-17 11:26:16 +04:00
|
|
|
*to++ = theChar;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*to = 0;
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
return to - (PRUnichar*)aString;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
typedef PRInt32 (*CompressChars)(char* aString,PRUint32 aCount,const char* aSet);
|
1999-03-22 12:54:46 +03:00
|
|
|
CompressChars gCompressChars[]={&CompressChars1,&CompressChars2};
|
|
|
|
|
1999-09-30 08:03:49 +04:00
|
|
|
/**
|
|
|
|
* This method strips chars in a given set from the given buffer
|
|
|
|
*
|
2000-02-11 15:11:03 +03:00
|
|
|
* @update gess 01/04/99
|
1999-09-30 08:03:49 +04:00
|
|
|
* @param aString is the buffer to be manipulated
|
|
|
|
* @param aLength is the length of the buffer
|
|
|
|
* @param aSet tells us which chars to compress from given buffer
|
|
|
|
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
|
|
|
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
|
|
|
* @return the new length of the given buffer
|
|
|
|
*/
|
|
|
|
PRInt32 StripChars1(char* aString,PRUint32 aLength,const char* aSet){
|
|
|
|
|
1999-11-14 09:22:52 +03:00
|
|
|
char* to = aString;
|
|
|
|
char* from = aString-1;
|
|
|
|
char* end = aString + aLength;
|
1999-09-30 08:03:49 +04:00
|
|
|
|
|
|
|
if(aSet && aString && (0 < aLength)){
|
|
|
|
PRUint32 aSetLen=strlen(aSet);
|
|
|
|
while (++from < end) {
|
1999-11-14 09:22:52 +03:00
|
|
|
char theChar = *from;
|
2000-02-11 15:11:03 +03:00
|
|
|
if(kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen)){
|
1999-09-30 08:03:49 +04:00
|
|
|
*to++ = theChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*to = 0;
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
return to - (char*)aString;
|
1999-09-30 08:03:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method strips chars in a given set from the given buffer
|
|
|
|
*
|
2000-02-11 15:11:03 +03:00
|
|
|
* @update gess 01/04/99
|
1999-09-30 08:03:49 +04:00
|
|
|
* @param aString is the buffer to be manipulated
|
|
|
|
* @param aLength is the length of the buffer
|
|
|
|
* @param aSet tells us which chars to compress from given buffer
|
|
|
|
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
|
|
|
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
|
|
|
* @return the new length of the given buffer
|
|
|
|
*/
|
|
|
|
PRInt32 StripChars2(char* aString,PRUint32 aLength,const char* aSet){
|
|
|
|
|
1999-11-14 09:22:52 +03:00
|
|
|
PRUnichar* to = (PRUnichar*)aString;
|
|
|
|
PRUnichar* from = (PRUnichar*)aString-1;
|
|
|
|
PRUnichar* end = to + aLength;
|
1999-09-30 08:03:49 +04:00
|
|
|
|
|
|
|
if(aSet && aString && (0 < aLength)){
|
|
|
|
PRUint32 aSetLen=strlen(aSet);
|
|
|
|
while (++from < end) {
|
1999-11-14 09:22:52 +03:00
|
|
|
PRUnichar theChar = *from;
|
|
|
|
//Note the test for ascii range below. If you have a real unicode char,
|
|
|
|
//and you're searching for chars in the (given) ascii string, there's no
|
|
|
|
//point in doing the real search since it's out of the ascii range.
|
2000-02-11 15:11:03 +03:00
|
|
|
if((255<theChar) || (kNotFound==FindChar1(aSet,aSetLen,0,theChar,PR_FALSE,aSetLen))){
|
1999-09-30 08:03:49 +04:00
|
|
|
*to++ = theChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*to = 0;
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
return to - (PRUnichar*)aString;
|
1999-09-30 08:03:49 +04:00
|
|
|
}
|
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
|
1999-09-30 08:03:49 +04:00
|
|
|
typedef PRInt32 (*StripChars)(char* aString,PRUint32 aCount,const char* aSet);
|
|
|
|
StripChars gStripChars[]={&StripChars1,&StripChars2};
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
#endif
|