зеркало из https://github.com/mozilla/pjs.git
Bug 334009 - Make unicharutils available to frozen (dependent) linkage components, r=darin+smontagu
This commit is contained in:
Родитель
cdf2d564bc
Коммит
7f6e3257e6
|
@ -225,6 +225,8 @@ intl/lwbrk/src/Makefile
|
|||
intl/lwbrk/public/Makefile
|
||||
intl/lwbrk/tests/Makefile
|
||||
intl/unicharutil/Makefile
|
||||
intl/unicharutil/util/Makefile
|
||||
intl/unicharutil/util/internal/Makefile
|
||||
intl/unicharutil/idl/Makefile
|
||||
intl/unicharutil/src/Makefile
|
||||
intl/unicharutil/public/Makefile
|
||||
|
|
|
@ -42,14 +42,16 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
# This makefile builds the unicharutil_external_s library which should be used
|
||||
# by frozen (dependent) linkage components. Internal-linkage code should use
|
||||
# unicharutil_s which is built in the internal/ subdirectory.
|
||||
|
||||
DIRS = internal
|
||||
|
||||
include $(srcdir)/objs.mk
|
||||
|
||||
EXTRA_DEPS += $(srcdir)/objs.mk
|
||||
|
||||
MODULE=unicharutil
|
||||
LIBRARY_NAME=unicharutil_s
|
||||
EXPORT_LIBRARY=1
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
LIBRARY_NAME=unicharutil_external_s
|
||||
DIST_INSTALL = 1
|
||||
|
||||
REQUIRES=xpcom \
|
||||
|
@ -62,7 +64,9 @@ EXPORTS = \
|
|||
nsCompressedCharMap.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = $(INTL_UNICHARUTIL_UTIL_LCPPSRCS)
|
||||
CPPSRCS = \
|
||||
nsUnicharUtils.cpp \
|
||||
$(NULL)
|
||||
|
||||
FORCE_STATIC_LIB = 1
|
||||
FORCE_USE_PIC = 1
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla 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/MPL/
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# the Mozilla Foundation <http://www.mozilla.org>.
|
||||
#
|
||||
# Portions created by the Initial Developer are Copyright (C) 2006
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Benjamin Smedberg <benjamin@smedbergs.us> (Original Code)
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
# This makefile builds the version of unicharutils_s static library which uses
|
||||
# internal linkage. Components that use frozen (external) linkage should use
|
||||
# unicharutil_external_s.
|
||||
|
||||
MODULE=unicharutil
|
||||
LIBRARY_NAME=unicharutil_s
|
||||
DIST_INSTALL = 1
|
||||
EXPORT_LIBRART = 1
|
||||
MOZILLA_INTERNAL_API = 1
|
||||
|
||||
include $(srcdir)/../objs.mk
|
||||
|
||||
EXTRA_DEPS += $(srcdir)/../objs.mk
|
||||
|
||||
REQUIRES=xpcom \
|
||||
string \
|
||||
uconv \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = $(INTL_UNICHARUTIL_UTIL_LCPPSRCS)
|
||||
|
||||
FORCE_STATIC_LIB = 1
|
||||
FORCE_USE_PIC = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
$(INTL_UNICHARUTIL_UTIL_LCPPSRCS): %: $(srcdir)/../%
|
||||
$(INSTALL) $^ .
|
|
@ -21,6 +21,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
* Benjamin Smedberg <benjamin@smedbergs.us>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -36,16 +37,20 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsICaseConversion.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCRTGlue.h"
|
||||
#include "nsXPCOMStrings.h"
|
||||
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
// global cache of the case conversion service
|
||||
static nsICaseConversion *gCaseConv = nsnull;
|
||||
|
||||
|
@ -59,7 +64,7 @@ public:
|
|||
NS_IMETHOD Observe(nsISupports *aSubject, const char *aTopic,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
if (nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)==0) {
|
||||
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)==0) {
|
||||
NS_IF_RELEASE(gCaseConv);
|
||||
}
|
||||
|
||||
|
@ -90,178 +95,71 @@ static nsresult NS_InitCaseConversion() {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class ConvertToLowerCase
|
||||
{
|
||||
public:
|
||||
typedef PRUnichar value_type;
|
||||
|
||||
ConvertToLowerCase()
|
||||
{
|
||||
NS_InitCaseConversion();
|
||||
}
|
||||
|
||||
PRUint32 write( const PRUnichar* aSource, PRUint32 aSourceLength)
|
||||
{
|
||||
if (gCaseConv)
|
||||
gCaseConv->ToLower(aSource, NS_CONST_CAST(PRUnichar*,aSource), aSourceLength);
|
||||
else
|
||||
NS_WARNING("No case converter: no conversion done");
|
||||
|
||||
return aSourceLength;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef MOZ_V1_STRING_ABI
|
||||
void
|
||||
ToLowerCase( nsAString& aString )
|
||||
{
|
||||
nsAString::iterator fromBegin, fromEnd;
|
||||
ConvertToLowerCase converter;
|
||||
copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd), converter);
|
||||
NS_InitCaseConversion();
|
||||
if (gCaseConv) {
|
||||
PRUnichar *buf = aString.BeginWriting();
|
||||
gCaseConv->ToLower(buf, buf, aString.Length());
|
||||
}
|
||||
else
|
||||
NS_WARNING("No case converter: no conversion done");
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ToLowerCase( nsASingleFragmentString& aString )
|
||||
{
|
||||
ConvertToLowerCase converter;
|
||||
PRUnichar* start;
|
||||
converter.write(aString.BeginWriting(start), aString.Length());
|
||||
}
|
||||
|
||||
void
|
||||
ToLowerCase( nsString& aString )
|
||||
{
|
||||
ConvertToLowerCase converter;
|
||||
PRUnichar* start;
|
||||
converter.write(aString.BeginWriting(start), aString.Length());
|
||||
}
|
||||
|
||||
class CopyToLowerCase
|
||||
{
|
||||
public:
|
||||
typedef PRUnichar value_type;
|
||||
|
||||
CopyToLowerCase( nsAString::iterator& aDestIter )
|
||||
: mIter(aDestIter)
|
||||
{
|
||||
NS_InitCaseConversion();
|
||||
}
|
||||
|
||||
PRUint32 write( const PRUnichar* aSource, PRUint32 aSourceLength )
|
||||
{
|
||||
PRUint32 len = PR_MIN(PRUint32(mIter.size_forward()), aSourceLength);
|
||||
PRUnichar* dest = mIter.get();
|
||||
if (gCaseConv)
|
||||
gCaseConv->ToLower(aSource, dest, len);
|
||||
else {
|
||||
NS_WARNING("No case converter: only copying");
|
||||
memcpy(dest, aSource, len * sizeof(*aSource));
|
||||
}
|
||||
mIter.advance(len);
|
||||
return len;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsAString::iterator& mIter;
|
||||
};
|
||||
|
||||
void
|
||||
ToLowerCase( const nsAString& aSource, nsAString& aDest )
|
||||
{
|
||||
nsAString::const_iterator fromBegin, fromEnd;
|
||||
nsAString::iterator toBegin;
|
||||
aDest.SetLength(aSource.Length());
|
||||
CopyToLowerCase converter(aDest.BeginWriting(toBegin));
|
||||
copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd), converter);
|
||||
NS_InitCaseConversion();
|
||||
|
||||
const PRUnichar *in;
|
||||
PRUint32 len = NS_StringGetData(aSource, &in);
|
||||
|
||||
PRUnichar *out;
|
||||
NS_StringGetMutableData(aDest, len, &out);
|
||||
|
||||
if (out && gCaseConv) {
|
||||
gCaseConv->ToLower(in, out, len);
|
||||
}
|
||||
else {
|
||||
NS_WARNING("No case converter: only copying");
|
||||
aDest.Assign(aSource);
|
||||
}
|
||||
}
|
||||
|
||||
class ConvertToUpperCase
|
||||
{
|
||||
public:
|
||||
typedef PRUnichar value_type;
|
||||
|
||||
ConvertToUpperCase()
|
||||
{
|
||||
NS_InitCaseConversion();
|
||||
}
|
||||
|
||||
PRUint32 write( const PRUnichar* aSource, PRUint32 aSourceLength)
|
||||
{
|
||||
if (gCaseConv)
|
||||
gCaseConv->ToUpper(aSource, NS_CONST_CAST(PRUnichar*,aSource), aSourceLength);
|
||||
else
|
||||
NS_WARNING("No case converter: no conversion done");
|
||||
|
||||
return aSourceLength;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef MOZ_V1_STRING_ABI
|
||||
void
|
||||
ToUpperCase( nsAString& aString )
|
||||
{
|
||||
nsAString::iterator fromBegin, fromEnd;
|
||||
ConvertToUpperCase converter;
|
||||
copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd), converter);
|
||||
NS_InitCaseConversion();
|
||||
if (gCaseConv) {
|
||||
PRUnichar *buf = aString.BeginWriting();
|
||||
gCaseConv->ToUpper(buf, buf, aString.Length());
|
||||
}
|
||||
else
|
||||
NS_WARNING("No case converter: no conversion done");
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ToUpperCase( nsASingleFragmentString& aString )
|
||||
{
|
||||
ConvertToUpperCase converter;
|
||||
PRUnichar* start;
|
||||
converter.write(aString.BeginWriting(start), aString.Length());
|
||||
}
|
||||
|
||||
void
|
||||
ToUpperCase( nsString& aString )
|
||||
{
|
||||
ConvertToUpperCase converter;
|
||||
PRUnichar* start;
|
||||
converter.write(aString.BeginWriting(start), aString.Length());
|
||||
}
|
||||
|
||||
class CopyToUpperCase
|
||||
{
|
||||
public:
|
||||
typedef PRUnichar value_type;
|
||||
|
||||
CopyToUpperCase( nsAString::iterator& aDestIter )
|
||||
: mIter(aDestIter)
|
||||
{
|
||||
NS_InitCaseConversion();
|
||||
}
|
||||
|
||||
PRUint32 write( const PRUnichar* aSource, PRUint32 aSourceLength )
|
||||
{
|
||||
PRUint32 len = PR_MIN(PRUint32(mIter.size_forward()), aSourceLength);
|
||||
PRUnichar* dest = mIter.get();
|
||||
if (gCaseConv)
|
||||
gCaseConv->ToUpper(aSource, dest, len);
|
||||
else {
|
||||
NS_WARNING("No case converter: only copying");
|
||||
memcpy(dest, aSource, len * sizeof(*aSource));
|
||||
}
|
||||
mIter.advance(len);
|
||||
return len;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsAString::iterator& mIter;
|
||||
};
|
||||
|
||||
void
|
||||
ToUpperCase( const nsAString& aSource, nsAString& aDest )
|
||||
{
|
||||
nsAString::const_iterator fromBegin, fromEnd;
|
||||
nsAString::iterator toBegin;
|
||||
aDest.SetLength(aSource.Length());
|
||||
CopyToUpperCase converter(aDest.BeginWriting(toBegin));
|
||||
copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd), converter);
|
||||
NS_InitCaseConversion();
|
||||
|
||||
const PRUnichar *in;
|
||||
PRUint32 len = NS_StringGetData(aSource, &in);
|
||||
|
||||
PRUnichar *out;
|
||||
NS_StringGetMutableData(aDest, len, &out);
|
||||
|
||||
if (out && gCaseConv) {
|
||||
gCaseConv->ToUpper(in, out, len);
|
||||
}
|
||||
else {
|
||||
NS_WARNING("No case converter: only copying");
|
||||
aDest.Assign(aSource);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
int
|
||||
nsCaseInsensitiveStringComparator::operator()( const PRUnichar* lhs, const PRUnichar* rhs, PRUint32 aLength ) const
|
||||
{
|
||||
|
@ -301,6 +199,19 @@ nsCaseInsensitiveStringComparator::operator()( PRUnichar lhs, PRUnichar rhs ) co
|
|||
if (lhs < rhs) return -1;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
PRInt32
|
||||
CaseInsensitiveCompare(const PRUnichar *a, const PRUnichar *b, PRUint32 len)
|
||||
{
|
||||
if (NS_FAILED(NS_InitCaseConversion()))
|
||||
return NS_strcmp(a, b);
|
||||
|
||||
PRInt32 result;
|
||||
gCaseConv->CaseInsensitiveCompare(a, b, len, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // MOZILLA_INTERNAL_API
|
||||
|
||||
PRUnichar
|
||||
ToLowerCase(PRUnichar aChar)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
* Benjamin Smedberg <benjamin@smedbergs.us>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -38,28 +39,16 @@
|
|||
|
||||
#ifndef nsUnicharUtils_h__
|
||||
#define nsUnicharUtils_h__
|
||||
#ifndef nsAString_h___
|
||||
#include "nsAString.h"
|
||||
#endif
|
||||
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
#ifndef nsCharTraits_h___
|
||||
#include "nsCharTraits.h"
|
||||
#endif
|
||||
#include "nsStringGlue.h"
|
||||
|
||||
void ToLowerCase( nsAString& );
|
||||
void ToUpperCase( nsAString& );
|
||||
|
||||
void ToLowerCase( nsASingleFragmentString& );
|
||||
void ToUpperCase( nsASingleFragmentString& );
|
||||
|
||||
void ToLowerCase( nsString& );
|
||||
void ToUpperCase( nsString& );
|
||||
|
||||
void ToLowerCase( const nsAString& aSource, nsAString& aDest );
|
||||
void ToUpperCase( const nsAString& aSource, nsAString& aDest );
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
class nsCaseInsensitiveStringComparator
|
||||
: public nsStringComparator
|
||||
{
|
||||
|
@ -83,6 +72,10 @@ inline PRBool CaseInsensitiveFindInReadable( const nsAString& aPattern,
|
|||
aHay.EndReading(searchEnd),
|
||||
nsCaseInsensitiveStringComparator());
|
||||
}
|
||||
#else
|
||||
NS_HIDDEN_(PRInt32)
|
||||
CaseInsensitiveCompare(const PRUnichar *a, const PRUnichar *b, PRUint32 len);
|
||||
#endif // MOZILLA_INTERNAL_API
|
||||
|
||||
PRUnichar ToUpperCase(PRUnichar);
|
||||
PRUnichar ToLowerCase(PRUnichar);
|
||||
|
|
Загрузка…
Ссылка в новой задаче