Hi,
This is a patch for several string related problems:

- Convert.ToString() for int handles '-'
- ByteString.Compare() + tests fix
- CString.IndexOf() + test
- PString.Concat had inverted assert
- CommandLine:
- - GetArgumentLength had inverted assert
- - argument index search stopping was inverted

It's working, has been tested and makes '-keymap XX' on kernel load
work again, but also removes some checks in CString, ByteString -
please review before commit.
Fixes IndexOf() test on dist-test build.
Index: Kernel/Core/Foundation/ByteString.cs
===================================================================
--- Kernel/Core/Foundation/ByteString.cs	(wersja 725)
+++ Kernel/Core/Foundation/ByteString.cs	(kopia robocza)
@@ -90,7 +90,7 @@
 		public static int Compare (byte* a, int aFrom, byte* b, int bFrom, int count)
 		{
 			int c = count;
-			int aLength = ByteString.Length (a), bLength = ByteString.Length (b);
+			int aLength = ByteString.Length (a + aFrom), bLength = ByteString.Length (b + bFrom);
 
 			if (count == 0 && aLength != bLength)
 				return aLength - bLength;
@@ -114,12 +114,12 @@
 		public static int Compare (byte* a, int aFrom, string b, int bFrom, int count)
 		{
 			int c = count;
-			int aLength = ByteString.Length (a);
+			int aLength = ByteString.Length (a + aFrom), bLength = b.Length - bFrom;
 
-			if (count == 0 && aLength != b.Length) {
-				return aLength - b.Length;
-			} else if (count != 0 && (aFrom + count > aLength || bFrom + count > b.Length)) {
-				return aLength - b.Length;
+			if (count == 0 && aLength != bLength) {
+				return aLength - bLength;
+			} else if (count != 0 && (aFrom + count > aLength || bFrom + count > bLength)) {
+				return aLength - bLength;
 			}
 
 			if (c == 0)
@@ -183,8 +183,11 @@
 				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'U[S]' == 'U[S]'");
 
 			if (ByteString.Compare (longer, 4, ptr1, 0, 2) != 0)
-				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'The [US]' == 'US'");
+				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'The [US]' == 'US' (count=2)");
 
+			if (ByteString.Compare (longer, 4, ptr1, 0, 0) != 0)
+				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'The [US]' == 'US' (count=0)");
+
 			//Test constant CString buffer with constant String type
 
 			if (ByteString.Compare (ptr1, "SK") == 0)
@@ -194,8 +197,11 @@
 				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'US' == const 'US'");
 
 			if (ByteString.Compare (longer, 4, "US", 0, 2) != 0)
-				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'The [US]' == const 'US'");
+				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'The [US]' == const 'US' (count=2)");
 
+			if (ByteString.Compare (longer, 4, "US", 0, 0) != 0)
+				TextMode.WriteLine ("ByteString.Compare(): test FAIL: 'The [US]' == const 'US' (count=0)");
+
 			//Test that constant String is working properly
 			const string str1 = "US";
 			const string str2 = "SK";
Index: Kernel/Core/Foundation/Convert.cs
===================================================================
--- Kernel/Core/Foundation/Convert.cs	(wersja 725)
+++ Kernel/Core/Foundation/Convert.cs	(kopia robocza)
@@ -48,6 +48,7 @@
 
 			if (!hex && value < 0) {
 				count++;
+				negative = true;
 
 				uvalue = (uint) -value;
 			}
Index: Kernel/Core/Foundation/CString8.cs
===================================================================
--- Kernel/Core/Foundation/CString8.cs	(wersja 725)
+++ Kernel/Core/Foundation/CString8.cs	(kopia robocza)
@@ -99,14 +99,14 @@
 				"CString8.IndexOf(): argument `substr' is null");
 			Diagnostics.Assert (offset >= 0 && offset < substrLen,
 				"CString8.IndexOf(): argument `offset' is out of range");
-			Diagnostics.Assert (count >= 0 && from + count < Length && from + count < substrLen,
+			Diagnostics.Assert (count >= 0 && from + count < Length,
 				"CString8.IndexOf(): argument `count' is out of range");
 
 			if (count == 0)
 				count = Length - substrLen - offset;
 
-			for (int x = from; x < from + count; ++x) {
-				if (x + substrLen >= Length)
+			for (int x = from; x <= from + count; ++x) {
+				if (x + substrLen > Length)
 					break;
 
 				if (Compare (x, substr, offset, substrLen) == 0) {
@@ -511,11 +511,19 @@
 		{
 			CString8* buf = (CString8*) Stubs.CString ("--keymap arg");
 
-			if (buf->IndexOf ("--keymap") != 0)
-				TextMode.WriteLine ("CString8.IndexOf(): test FAIL: result should be 0");
+			if (buf->Compare ("--keymap", 8) != 0)
+				TextMode.WriteLine ("CString8.Compare(): test[1] FAIL: result should be 0");
 
-			if (buf->IndexOf ("arg") != 9)
-				TextMode.WriteLine ("CString8.IndexOf(): test FAIL: result should be 9");
+			if (buf->Compare (9, "arg", 0, 0) != 0)
+				TextMode.WriteLine ("CString8.Compare(): test[2] FAIL: result should be 0");
+			
+			int ind = buf->IndexOf ("--keymap"); 
+			if (ind != 0)
+				TextMode.Write ("CString8.IndexOf(): test[3] FAIL: result should be 0");
+
+			ind = buf->IndexOf ("arg");
+			if (ind != 9)
+				TextMode.Write ("CString8.IndexOf(): test[4] FAIL: result should be 9");
 		}
 
 		#endregion
Index: Kernel/Core/Foundation/PString8.cs
===================================================================
--- Kernel/Core/Foundation/PString8.cs	(wersja 725)
+++ Kernel/Core/Foundation/PString8.cs	(kopia robocza)
@@ -62,7 +62,7 @@
 			if (len == 0)
 				len = strLen - offset;
 
-			Diagnostics.Assert (offset + len >= strLen, "PString8.Concat(): offset + len >= strLen");
+			Diagnostics.Assert (offset + len <= strLen, "PString8.Concat(): offset + len <= strLen");
 
 			for (int x = offset; x < strLen && (x - offset) < len; ++x)
 				Concat (str [x]);
Index: Kernel/Core/CommandLine.cs
===================================================================
--- Kernel/Core/CommandLine.cs	(wersja 725)
+++ Kernel/Core/CommandLine.cs	(kopia robocza)
@@ -119,8 +119,8 @@
 				return -1;
 
 			while (argumentIndex < commandLine->Length) {
-				if (commandLine->GetChar (argumentIndex) != ' ')
-					return argumentIndex;
+				if (commandLine->GetChar (argumentIndex) == ' ')
+					return argumentIndex+1;
 
 				++argumentIndex;
 			}
@@ -132,7 +132,7 @@
 		{
 			int x = argumentIndex;
 
-			Diagnostics.Assert (argumentIndex < 0 || argumentIndex >= commandLine->Length,
+			Diagnostics.Assert (argumentIndex >= 0 && argumentIndex < commandLine->Length,
 				"CommandLine.GetArgumentLength(): argument `argumentIndex' is out of range");
 
 			while (x < commandLine->Length && commandLine->GetChar (x) != ' ')
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
SharpOS-Developers mailing list
SharpOS-Developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sharpos-developers

Reply via email to