landing 172512. nsEmbedString for component developers and embeders. r=alec, sr=jag/darin, a=asa@mozilla.org

This commit is contained in:
dougt%netscape.com 2002-10-17 23:41:47 +00:00
parent 12dab86278
commit 20cb222459
16 changed files with 712 additions and 38 deletions

View File

@ -30,13 +30,17 @@ include $(DEPTH)/config/autoconf.mk
MODULE = string
SDK_HEADERS = \
nsAString.h \
nsBufferHandle.h \
nsStringFragment.h \
$(NULL)
EXPORTS = \
nsAFlatString.h \
nsAlgorithm.h \
nsASingleFragmentString.h \
nsAString.h \
nsAStringGenerator.h \
nsBufferHandle.h \
nsBufferHandleUtils.h \
nsCharTraits.h \
nsDependentConcatenation.h \
@ -51,7 +55,6 @@ EXPORTS = \
nsSharedBufferList.h \
nsSlidingString.h \
nsStringDefines.h \
nsStringFragment.h \
nsStringFwd.h \
nsStringIterator.h \
nsStringIteratorUtils.h \

View File

@ -24,7 +24,7 @@
#include "nsAString.h"
#include "nsDependentSubstring.h"
#include "nsDependentString.h"
#include "nsCRT.h"
#include "plstr.h"
int
@ -520,7 +520,12 @@ nsDefaultCStringComparator::operator()( char_type lhs, char_type rhs ) const
int
nsCaseInsensitiveCStringComparator::operator()( const char_type* lhs, const char_type* rhs, PRUint32 aLength ) const
{
return nsCRT::strncasecmp(lhs, rhs, aLength);
PRInt32 result=PRInt32(PL_strncasecmp(lhs, rhs, aLength));
//Egads. PL_strncasecmp is returning *very* negative numbers.
//Some folks expect -1,0,1, so let's temper its enthusiasm.
if (result<0)
result=-1;
return result;
}
PRBool

View File

@ -49,6 +49,18 @@
*/
#define NS_DIRECTORY_SERVICE_CONTRACTID "@mozilla.org/file/directory_service;1"
/**
* XPCOM File
* The file abstraction provides ways to obtain and access files and
* directories located on the local system.
*
* This contract supports the nsIFile interface and the nsILocalFile interface.
* This contract may also support platform specific interfaces such as
* nsILocalFileMac on platforms where additional interfaces are required.
*
*/
#define NS_LOCAL_FILE_CONTRACTID "@mozilla.org/file/local;1"
/**
* XPCOM Category Manager Contract ID
* The contract supports the nsICategoryManager interface. The

View File

@ -351,7 +351,7 @@ static const nsModuleComponentInfo components[] = {
COMPONENT_SUPPORTS(INTERFACE_POINTER, InterfacePointer),
#undef COMPONENT_SUPPORTS
#define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
COMPONENT(LOCAL_FILE, nsLocalFile::nsLocalFileConstructor),
#define NS_DIRECTORY_SERVICE_CLASSNAME "nsIFile Directory Service"
COMPONENT(DIRECTORY_SERVICE, nsDirectoryService::Create),

View File

@ -51,6 +51,7 @@
#include "nsIFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryService.h"
#include "nsEmbedString.h"
#endif
nsGenericFactory::nsGenericFactory(const nsModuleComponentInfo *info)
@ -297,7 +298,7 @@ nsGenericModule::Initialize(nsIComponentManager *compMgr)
if (NS_FAILED(rv))
return rv;
nsCAutoString path;
nsEmbedCString path;
xpcomDll->GetNativePath(path);
rv = XPCOMGlueStartup(path.get());

View File

@ -48,21 +48,34 @@ LIBRARY_NAME = xpcomglue
REQUIRES = string \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/../../build \
$(NULL)
STRING_LCSRCS = \
nsAString.cpp \
nsDependentSubstring.cpp \
nsASingleFragmentString.cpp \
$(NULL)
STRING_CSRCS := $(addprefix $(topsrcdir)/string/src/, $(STRING_LCSRCS))
CPPSRCS = \
$(XPCOM_GLUE_SRC_LCSRCS) \
nsXPCOMGlue.cpp \
$(XPCOM_GLUE_SRC_LCSRCS) \
$(STRING_LCSRCS) \
nsXPCOMGlue.cpp \
nsEmbedString.cpp \
$(NULL)
EXPORTS = \
nsXPCOMGlue.h \
$(NULL)
SDK_BINARY = \
SDK_HEADERS = \
nsEmbedString.h \
$(NULL)
SDK_BINARY = \
$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
$(NULL)
@ -73,9 +86,11 @@ FORCE_STATIC_LIB = 1
FORCE_USE_PIC = 1
GARBAGE += $(XPCOM_GLUE_SRC_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))
GARBAGE += $(STRING_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))
ifeq ($(OS_ARCH),WINNT)
GARBAGE += $(addprefix $(srcdir)/,$(XPCOM_GLUE_SRC_LCSRCS))
GARBAGE += $(addprefix $(srcdir)/,$(STRING_LCSRCS))
endif
include $(topsrcdir)/config/rules.mk
@ -87,6 +102,13 @@ else
$(INSTALL) $^ .
endif
export:: $(STRING_CSRCS)
ifeq ($(OS_ARCH),WINNT)
$(INSTALL) $^ $(srcdir)
else
$(INSTALL) $^ .
endif
DEFINES += -DXPCOM_GLUE

View File

@ -0,0 +1,456 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 a small implementation of the nsAString and nsACString.
*
* The Initial Developer of the Original Code is
* Peter Annema <jaggernaut@netscape.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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
* 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 ***** */
#include "nsEmbedString.h"
#include "nsMemory.h"
const PRUnichar gCommonEmptyBuffer[1] = { 0 };
nsEmbedString::nsEmbedString()
{
Init();
}
nsEmbedString::nsEmbedString(const char_type* aString)
{
Init();
Assign(aString);
}
nsEmbedString::nsEmbedString(const char_type* aString, size_type aLength)
{
Init();
Assign(aString, aLength);
}
nsEmbedString::nsEmbedString(const nsEmbedString& aString)
{
Init();
Assign(aString);
}
nsEmbedString::nsEmbedString(const abstract_string_type& aReadable)
{
Init();
Assign(aReadable);
}
nsEmbedString::~nsEmbedString()
{
Destroy();
}
void
nsEmbedString::Init()
{
mStr = (char_type*)gCommonEmptyBuffer;
mLength = 0;
mCapacity = 0;
}
void
nsEmbedString::Destroy()
{
Free();
}
void
nsEmbedString::Free()
{
if (OwnsBuffer())
nsMemory::Free(mStr);
}
PRBool
nsEmbedString::Realloc(size_type aNewSize)
{
PRBool result = PR_TRUE;
if (OwnsBuffer())
{
char_type* temp = (char_type*)nsMemory::Realloc(mStr, (aNewSize + 1) * sizeof(char_type));
if (temp)
{
mStr = temp;
mCapacity = aNewSize;
}
else
result = PR_FALSE;
}
else
{
char_type* temp = (char_type*)nsMemory::Alloc((aNewSize + 1) * sizeof(char_type));
if (temp)
{
memcpy(temp, mStr, mLength * sizeof(char_type));
mStr = temp;
mCapacity = aNewSize;
}
else
result = PR_FALSE;
}
return result;
}
PRBool
nsEmbedString::OwnsBuffer() const
{
return mStr != (char_type*)gCommonEmptyBuffer;
}
const nsEmbedString::char_type*
nsEmbedString::GetReadableFragment(const_fragment_type& aFragment, nsFragmentRequest aRequest, index_type aOffset) const
{
switch (aRequest) {
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
return aFragment.mStart + aOffset;
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
nsEmbedString::char_type*
nsEmbedString::GetWritableFragment(fragment_type& aFragment, nsFragmentRequest aRequest, index_type aOffset)
{
switch (aRequest) {
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
return aFragment.mStart + aOffset;
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
const nsEmbedString::buffer_handle_type*
nsEmbedString::GetFlatBufferHandle() const
{
return NS_REINTERPRET_CAST(const buffer_handle_type*, 1);
}
void
nsEmbedString::SetLength(size_type aLength)
{
if (aLength > mCapacity)
GrowCapacity(aLength);
mLength = aLength;
if (mStr != (char_type*)gCommonEmptyBuffer)
AddNullTerminator();
}
void
nsEmbedString::SetCapacity(size_type aNewCapacity)
{
if (aNewCapacity)
{
if (aNewCapacity > mCapacity)
GrowCapacity(aNewCapacity);
// AddNullTerminator(); // doesn't make sense
}
else
{
Destroy();
Init();
}
}
PRBool
nsEmbedString::EnsureCapacity(size_type aNewCapacity)
{
PRBool result = PR_TRUE;
if (aNewCapacity > mCapacity)
{
result = Realloc(aNewCapacity);
if (result)
AddNullTerminator();
}
return result;
}
PRBool
nsEmbedString::GrowCapacity(size_type aNewCapacity)
{
PRBool result = PR_TRUE;
if (mCapacity)
{
size_type newCapacity = mCapacity;
while (newCapacity < aNewCapacity)
newCapacity <<= 1;
aNewCapacity = newCapacity;
}
nsEmbedString temp;
result = temp.EnsureCapacity(aNewCapacity);
if (result)
{
if (mLength)
temp.Assign(*this);
Free();
mStr = temp.mStr;
temp.mStr = 0;
mLength = temp.mLength;
mCapacity = temp.mCapacity;
}
return result;
}
nsEmbedCString::nsEmbedCString()
{
Init();
}
nsEmbedCString::nsEmbedCString(const char_type* aString)
{
Init();
Assign(aString);
}
nsEmbedCString::nsEmbedCString(const char_type* aString, size_type aLength)
{
Init();
Assign(aString, aLength);
}
nsEmbedCString::nsEmbedCString(const nsEmbedCString& aString)
{
Init();
Assign(aString);
}
nsEmbedCString::nsEmbedCString(const abstract_string_type& aReadable)
{
Init();
Assign(aReadable);
}
nsEmbedCString::~nsEmbedCString()
{
Destroy();
}
void
nsEmbedCString::Init()
{
mStr = (char_type*)gCommonEmptyBuffer;
mLength = 0;
mCapacity = 0;
}
void
nsEmbedCString::Destroy()
{
Free();
}
void
nsEmbedCString::Free()
{
if (OwnsBuffer())
nsMemory::Free(mStr);
}
PRBool
nsEmbedCString::Realloc(size_type aNewSize)
{
PRBool result = PR_TRUE;
if (OwnsBuffer())
{
char_type* temp = (char_type*)nsMemory::Realloc(mStr, (aNewSize + 1) * sizeof(char_type));
if (temp)
{
mStr = temp;
mCapacity = aNewSize;
}
else
result = PR_FALSE;
}
else
{
char_type* temp = (char_type*)nsMemory::Alloc((aNewSize + 1) * sizeof(char_type));
if (temp)
{
memcpy(temp, mStr, mLength * sizeof(char_type));
mStr = temp;
mCapacity = aNewSize;
}
else
result = PR_FALSE;
}
return result;
}
PRBool
nsEmbedCString::OwnsBuffer() const
{
return mStr != (char_type*)gCommonEmptyBuffer;
}
const nsEmbedCString::char_type*
nsEmbedCString::GetReadableFragment(const_fragment_type& aFragment, nsFragmentRequest aRequest, index_type aOffset) const
{
switch (aRequest) {
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
return aFragment.mStart + aOffset;
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
nsEmbedCString::char_type*
nsEmbedCString::GetWritableFragment(fragment_type& aFragment, nsFragmentRequest aRequest, index_type aOffset)
{
switch (aRequest) {
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
aFragment.mEnd = (aFragment.mStart = mStr) + mLength;
return aFragment.mStart + aOffset;
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
const nsEmbedCString::buffer_handle_type*
nsEmbedCString::GetFlatBufferHandle() const
{
return NS_REINTERPRET_CAST(const buffer_handle_type*, 1);
}
void
nsEmbedCString::SetLength(size_type aLength)
{
if (aLength > mCapacity)
GrowCapacity(aLength);
mLength = aLength;
if (mStr != (char_type*)gCommonEmptyBuffer)
AddNullTerminator();
}
void
nsEmbedCString::SetCapacity(size_type aNewCapacity)
{
if (aNewCapacity)
{
if (aNewCapacity > mCapacity)
GrowCapacity(aNewCapacity);
// AddNullTerminator(); // doesn't make sense
}
else
{
Destroy();
Init();
}
}
PRBool
nsEmbedCString::EnsureCapacity(size_type aNewCapacity)
{
PRBool result = PR_TRUE;
if (aNewCapacity > mCapacity)
{
result = Realloc(aNewCapacity);
if (result)
AddNullTerminator();
}
return result;
}
PRBool
nsEmbedCString::GrowCapacity(size_type aNewCapacity)
{
PRBool result = PR_TRUE;
if (mCapacity)
{
size_type newCapacity = mCapacity;
while (newCapacity < aNewCapacity)
newCapacity <<= 1;
aNewCapacity = newCapacity;
}
nsEmbedCString temp;
result = temp.EnsureCapacity(aNewCapacity);
if (result)
{
if (mLength)
temp.Assign(*this);
Free();
mStr = temp.mStr;
temp.mStr = 0;
mLength = temp.mLength;
mCapacity = temp.mCapacity;
}
return result;
}

View File

@ -0,0 +1,148 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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 a small implementation of the nsAString and nsACString.
*
* The Initial Developer of the Original Code is
* Peter Annema <jaggernaut@netscape.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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
* 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 ***** */
#ifndef nsEmbedString_h__
#define nsEmbedString_h__
#include "nsAString.h"
class nsEmbedString : public nsAString
{
public:
typedef nsEmbedString self_type;
nsEmbedString();
nsEmbedString(const self_type& aString);
explicit nsEmbedString(const abstract_string_type&);
explicit nsEmbedString(const char_type*);
nsEmbedString(const char_type*, size_type);
virtual ~nsEmbedString();
virtual const char_type* get() const { return mStr; }
virtual size_type Length() const { return mLength; }
void SetLength(size_type aLength);
void SetCapacity(size_type aNewCapacity);
nsEmbedString& operator=(const self_type& aString) { Assign(aString); return *this; }
nsEmbedString& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
nsEmbedString& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
nsEmbedString& operator=(char_type aChar) { Assign(aChar); return *this; }
protected:
void Init();
void Destroy();
void Free();
PRBool EnsureCapacity(size_type);
PRBool GrowCapacity(size_type);
virtual PRBool OwnsBuffer() const;
void AddNullTerminator() { mStr[mLength] = 0; }
PRBool Realloc(size_type);
virtual const buffer_handle_type* GetFlatBufferHandle() const;
virtual const char_type* GetReadableFragment(const_fragment_type&, nsFragmentRequest, index_type) const;
virtual char_type* GetWritableFragment(fragment_type&, nsFragmentRequest, index_type);
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
void operator=(incompatible_char_type);
protected:
char_type* mStr;
size_type mLength;
size_type mCapacity;
};
class nsEmbedCString : public nsACString
{
public:
typedef nsEmbedCString self_type;
nsEmbedCString();
nsEmbedCString(const self_type& aString);
explicit nsEmbedCString(const abstract_string_type&);
explicit nsEmbedCString(const char_type*);
nsEmbedCString(const char_type*, size_type);
virtual ~nsEmbedCString();
virtual const char_type* get() const { return mStr; }
virtual size_type Length() const { return mLength; }
void SetLength(size_type aLength);
void SetCapacity(size_type aNewCapacity);
nsEmbedCString& operator=(const self_type& aString) { Assign(aString); return *this; }
nsEmbedCString& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
nsEmbedCString& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
nsEmbedCString& operator=(char_type aChar) { Assign(aChar); return *this; }
protected:
void Init();
void Destroy();
void Free();
PRBool EnsureCapacity(size_type);
PRBool GrowCapacity(size_type);
virtual PRBool OwnsBuffer() const;
void AddNullTerminator() { mStr[mLength] = 0; }
PRBool Realloc(size_type);
virtual const buffer_handle_type* GetFlatBufferHandle() const;
virtual const char_type* GetReadableFragment(const_fragment_type&, nsFragmentRequest, index_type) const;
virtual char_type* GetWritableFragment(fragment_type&, nsFragmentRequest, index_type);
private:
// NOT TO BE IMPLEMENTED
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
void operator=(incompatible_char_type);
protected:
char_type* mStr;
size_type mLength;
size_type mCapacity;
};
#endif // !nsEmbedString_h__

View File

@ -317,8 +317,6 @@ interface nsIFile : nsISupports
};
%{C++
#define NS_FILE_CONTRACTID "@mozilla.org/file;1"
#define NS_FILE_CLASSNAME "File Specification"
#ifndef MOZILLA_STRICT_API
#include "nsDirectoryServiceUtils.h"
#endif

View File

@ -170,8 +170,3 @@ interface nsILocalFile : nsIFile
void setRelativeDescriptor(in nsILocalFile fromFile, in ACString relativeDesc);
};
%{C++
#define NS_LOCAL_FILE_CONTRACTID "@mozilla.org/file/local;1"
#define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
%}

View File

@ -63,15 +63,11 @@ EXTRA_COMPONENTS = nsSample.js
# seperate libraries linked in.
EXTRA_DSO_LDOPTS = \
$(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
$(NSPR_LIBS) \
$(NULL)
LIBS = \
$(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
$(NSPR_LIBS) \
$(NULL)

View File

@ -47,16 +47,12 @@
#include "nsSample.h"
#include "nsMemory.h"
#ifdef XPCOM_GLUE
#include "nsXPCOMGlue.h"
#endif
#include "nsEmbedString.h"
////////////////////////////////////////////////////////////////////////
nsSampleImpl::nsSampleImpl() : mValue(nsnull)
{
#ifdef XPCOM_GLUE
XPCOMGlueStartup("XPCOMComponentGlue");
#endif
NS_INIT_ISUPPORTS();
mValue = (char*)nsMemory::Clone("initial value", 14);
}
@ -65,10 +61,6 @@ nsSampleImpl::~nsSampleImpl()
{
if (mValue)
nsMemory::Free(mValue);
#ifdef XPCOM_GLUE
XPCOMGlueShutdown();
#endif
}
/**
@ -150,6 +142,12 @@ nsSampleImpl::Poke(const char* aValue)
return SetValue((char*) aValue);
}
static void GetStringValue(nsACString& aValue)
{
aValue.Assign("GetValue");
}
NS_IMETHODIMP
nsSampleImpl::WriteValue(const char* aPrefix)
{
@ -158,5 +156,27 @@ nsSampleImpl::WriteValue(const char* aPrefix)
return NS_ERROR_NULL_POINTER;
printf("%s %s\n", aPrefix, mValue);
// This next part illustrates the nsEmbedString:
nsEmbedString foopy;
foopy.Append(PRUnichar('f'));
foopy.Append(PRUnichar('o'));
foopy.Append(PRUnichar('o'));
foopy.Append(PRUnichar('p'));
foopy.Append(PRUnichar('y'));
const PRUnichar* f = foopy.get();
PRUint32 l = foopy.Length();
printf("%c%c%c%c%c %d\n", char(f[0]), char(f[1]), char(f[2]), char(f[3]), char(f[4]), l);
nsEmbedCString foopy2;
GetStringValue(foopy2);
//foopy2.Append(NS_LITERAL_CSTRING("foopy"));
const char* f2 = foopy2.get();
PRUint32 l2 = foopy2.Length();
printf("%s %d\n", f2, l2);
return NS_OK;
}

View File

@ -51,6 +51,7 @@
#ifdef XPCOM_GLUE
#include "nsXPCOMGlue.h"
#include "nsMemory.h"
#endif
#define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
@ -114,8 +115,14 @@ main(void)
return -3;
}
printf("Set value to: %s\n", testValue);
#ifndef XPCOM_GLUE
nsXPIDLCString str;
rv = mysample->GetValue(getter_Copies(str));
#else
char *str;
rv = mysample->GetValue(&str);
#endif
if (NS_FAILED(rv))
{
printf("ERROR: Calling nsISample::GetValue() [%x]\n", rv);
@ -127,6 +134,9 @@ main(void)
return -4;
}
#ifdef XPCOM_GLUE
nsMemory::Free(str);
#endif
rv = mysample->WriteValue("Final print :");
printf("Test passed.\n");

View File

@ -30,13 +30,17 @@ include $(DEPTH)/config/autoconf.mk
MODULE = string
SDK_HEADERS = \
nsAString.h \
nsBufferHandle.h \
nsStringFragment.h \
$(NULL)
EXPORTS = \
nsAFlatString.h \
nsAlgorithm.h \
nsASingleFragmentString.h \
nsAString.h \
nsAStringGenerator.h \
nsBufferHandle.h \
nsBufferHandleUtils.h \
nsCharTraits.h \
nsDependentConcatenation.h \
@ -51,7 +55,6 @@ EXPORTS = \
nsSharedBufferList.h \
nsSlidingString.h \
nsStringDefines.h \
nsStringFragment.h \
nsStringFwd.h \
nsStringIterator.h \
nsStringIteratorUtils.h \

View File

@ -24,7 +24,7 @@
#include "nsAString.h"
#include "nsDependentSubstring.h"
#include "nsDependentString.h"
#include "nsCRT.h"
#include "plstr.h"
int
@ -520,7 +520,12 @@ nsDefaultCStringComparator::operator()( char_type lhs, char_type rhs ) const
int
nsCaseInsensitiveCStringComparator::operator()( const char_type* lhs, const char_type* rhs, PRUint32 aLength ) const
{
return nsCRT::strncasecmp(lhs, rhs, aLength);
PRInt32 result=PRInt32(PL_strncasecmp(lhs, rhs, aLength));
//Egads. PL_strncasecmp is returning *very* negative numbers.
//Some folks expect -1,0,1, so let's temper its enthusiasm.
if (result<0)
result=-1;
return result;
}
PRBool

View File

@ -268,7 +268,7 @@ DeletionTest(const char* creationPath, const char* appendPath, PRBool recursive)
{
nsCOMPtr<nsILocalFile> file;
nsresult rv =
nsComponentManager::CreateInstance(NS_FILE_CONTRACTID, NULL,
nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL,
NS_GET_IID(nsILocalFile),
(void**)getter_AddRefs(file));