From f8fb00ca597a2b4e9c4316375e4dfd613ea53ca7 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Sun, 10 Jan 1999 08:17:40 +0000 Subject: [PATCH] fixed bug in Compare() and error in ToInteger() git-svn-id: svn://10.0.0.236/trunk@17465 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/base/src/nsString.cpp | 17 ++++++++++++++--- mozilla/string/obsolete/nsString.cpp | 17 ++++++++++++++--- mozilla/xpcom/ds/nsString.cpp | 17 ++++++++++++++--- mozilla/xpcom/string/obsolete/nsString.cpp | 17 ++++++++++++++--- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/mozilla/base/src/nsString.cpp b/mozilla/base/src/nsString.cpp index 653044ea743..0b7b83e393b 100644 --- a/mozilla/base/src/nsString.cpp +++ b/mozilla/base/src/nsString.cpp @@ -623,7 +623,8 @@ float nsString::ToFloat(PRInt32* aErrorCode) const */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; - PRUnichar* cp = mStr + mLength-1; + PRInt32 decPt=Find(PRUnichar('.'),0); + PRUnichar* cp = (-1==decPt) ? mStr + mLength-1 : mStr+decPt-1; char digit=0; PRUnichar theChar; PRInt32 theShift=0; @@ -631,6 +632,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { *aErrorCode = (0= mStr) { theChar = *cp; @@ -1635,9 +1637,9 @@ PRInt32 nsString::Compare(const nsString &S,PRBool aIgnoreCase) const { return 1; } if (aIgnoreCase) { - return nsCRT::strncasecmp(mStr,S.mStr,maxlen); + return nsCRT::strcasecmp(mStr,S.mStr); } - return nsCRT::strncmp(mStr,S.mStr,maxlen); + return nsCRT::strcmp(mStr,S.mStr); } /** @@ -2060,6 +2062,15 @@ NS_BASE int fputs(const nsString& aString, FILE* out) * @return */ void nsString::SelfTest(void) { + + nsAutoString a("foobar"); + nsAutoString b("foo"); + nsAutoString c(".5111"); + PRInt32 result=a.Compare(b); + PRInt32 result2=result; + result=c.ToInteger(&result2); + result2=result; + #if 0 static const char* kConstructorError = kConstructorError; diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index 653044ea743..0b7b83e393b 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -623,7 +623,8 @@ float nsString::ToFloat(PRInt32* aErrorCode) const */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; - PRUnichar* cp = mStr + mLength-1; + PRInt32 decPt=Find(PRUnichar('.'),0); + PRUnichar* cp = (-1==decPt) ? mStr + mLength-1 : mStr+decPt-1; char digit=0; PRUnichar theChar; PRInt32 theShift=0; @@ -631,6 +632,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { *aErrorCode = (0= mStr) { theChar = *cp; @@ -1635,9 +1637,9 @@ PRInt32 nsString::Compare(const nsString &S,PRBool aIgnoreCase) const { return 1; } if (aIgnoreCase) { - return nsCRT::strncasecmp(mStr,S.mStr,maxlen); + return nsCRT::strcasecmp(mStr,S.mStr); } - return nsCRT::strncmp(mStr,S.mStr,maxlen); + return nsCRT::strcmp(mStr,S.mStr); } /** @@ -2060,6 +2062,15 @@ NS_BASE int fputs(const nsString& aString, FILE* out) * @return */ void nsString::SelfTest(void) { + + nsAutoString a("foobar"); + nsAutoString b("foo"); + nsAutoString c(".5111"); + PRInt32 result=a.Compare(b); + PRInt32 result2=result; + result=c.ToInteger(&result2); + result2=result; + #if 0 static const char* kConstructorError = kConstructorError; diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index 653044ea743..0b7b83e393b 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -623,7 +623,8 @@ float nsString::ToFloat(PRInt32* aErrorCode) const */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; - PRUnichar* cp = mStr + mLength-1; + PRInt32 decPt=Find(PRUnichar('.'),0); + PRUnichar* cp = (-1==decPt) ? mStr + mLength-1 : mStr+decPt-1; char digit=0; PRUnichar theChar; PRInt32 theShift=0; @@ -631,6 +632,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { *aErrorCode = (0= mStr) { theChar = *cp; @@ -1635,9 +1637,9 @@ PRInt32 nsString::Compare(const nsString &S,PRBool aIgnoreCase) const { return 1; } if (aIgnoreCase) { - return nsCRT::strncasecmp(mStr,S.mStr,maxlen); + return nsCRT::strcasecmp(mStr,S.mStr); } - return nsCRT::strncmp(mStr,S.mStr,maxlen); + return nsCRT::strcmp(mStr,S.mStr); } /** @@ -2060,6 +2062,15 @@ NS_BASE int fputs(const nsString& aString, FILE* out) * @return */ void nsString::SelfTest(void) { + + nsAutoString a("foobar"); + nsAutoString b("foo"); + nsAutoString c(".5111"); + PRInt32 result=a.Compare(b); + PRInt32 result2=result; + result=c.ToInteger(&result2); + result2=result; + #if 0 static const char* kConstructorError = kConstructorError; diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index 653044ea743..0b7b83e393b 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -623,7 +623,8 @@ float nsString::ToFloat(PRInt32* aErrorCode) const */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; - PRUnichar* cp = mStr + mLength-1; + PRInt32 decPt=Find(PRUnichar('.'),0); + PRUnichar* cp = (-1==decPt) ? mStr + mLength-1 : mStr+decPt-1; char digit=0; PRUnichar theChar; PRInt32 theShift=0; @@ -631,6 +632,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { *aErrorCode = (0= mStr) { theChar = *cp; @@ -1635,9 +1637,9 @@ PRInt32 nsString::Compare(const nsString &S,PRBool aIgnoreCase) const { return 1; } if (aIgnoreCase) { - return nsCRT::strncasecmp(mStr,S.mStr,maxlen); + return nsCRT::strcasecmp(mStr,S.mStr); } - return nsCRT::strncmp(mStr,S.mStr,maxlen); + return nsCRT::strcmp(mStr,S.mStr); } /** @@ -2060,6 +2062,15 @@ NS_BASE int fputs(const nsString& aString, FILE* out) * @return */ void nsString::SelfTest(void) { + + nsAutoString a("foobar"); + nsAutoString b("foo"); + nsAutoString c(".5111"); + PRInt32 result=a.Compare(b); + PRInt32 result2=result; + result=c.ToInteger(&result2); + result2=result; + #if 0 static const char* kConstructorError = kConstructorError;