[SCM] Lisaac compiler branch, master, updated. 8a95a9037204db4637f632201aeae1d16bf20a60
Jeremy Cowgar
jeremy at cowgar.com
Thu Mar 26 02:20:51 UTC 2009
The following commit has been merged in the master branch:
commit 8a95a9037204db4637f632201aeae1d16bf20a60
Author: Jeremy Cowgar <jeremy at cowgar.com>
Date: Wed Mar 25 22:07:58 2009 -0400
* Added to_string and to_string_in to CHARACTER.
* Documented a bit better what CHARACTER.is_separator does.
* Added index_of to ABSTRACT_STRING.
* Fixed bug in fast_index_of which would cause a "NOT FOUND"
value to be returned if the character only appeared on the
first character of the string.
* Uncommented the character test in UNIT_TEST now that CHARACTER
has a to_string slot.
diff --git a/lib/base/character.li b/lib/base/character.li
index d54a59e..47b7629 100644
--- a/lib/base/character.li
+++ b/lib/base/character.li
@@ -327,7 +327,7 @@ Section Public
);
- is_separator:BOOLEAN <-
- // True when character is a separator.
+ // True when character is a separator (' ', '\t', '\n', '\r', '\0', '\f', '\v')?
(
(Self= ' ') || {Self = '\t'} || {Self='\n'} ||
{Self='\r'} || {Self = '\0'} || {Self='\f'} || {Self='\v'}
@@ -362,7 +362,21 @@ Section Public
//
// Conversions:
//
-
+
+ - to_string:STRING <-
+ // Create a new STRING containing only this character.
+ (
+ STRING.create_filled (Self,1)
+ );
+
+ - to_string_in str:STRING <-
+ // Append this character at the end of 'str'. Thus you
+ // can save memory because no other STRING is allocated
+ // for the job.
+ (
+ str.append_character str;
+ );
+
- to_hexadecimal:STRING <-
// Create a new STRING giving the `code' in hexadecimal.
// For example :
diff --git a/lib/string/abstract_string.li b/lib/string/abstract_string.li
index 6404c54..79e1ea2 100644
--- a/lib/string/abstract_string.li
+++ b/lib/string/abstract_string.li
@@ -26,7 +26,7 @@ Section Header
- copyright := "2003-2005 Jérome Boutet, 2003-2007 Benoit Sonntag";
- - comment := "Generic prototype for STRING and STRING_CONSTANT";
+ - comment := "Generic prototype for STRING and STRING_CONSTANT. Strings are 1 based index.";
Section Inherit
@@ -213,7 +213,7 @@ Section Public
);
- last_index_of ch:CHARACTER since start_index:INTEGER :INTEGER <-
- // Index of first occurrence of `c' at or before `start_index',
+ // Index of last occurrence of `ch' at or before `start_index',
// 0 if none.
( + result:INTEGER;
? {start_index.in_range 0 to upper};
@@ -232,10 +232,17 @@ Section Public
// Gives the index of the first occurrence `ch' or
// 0 if none.
(+ result:INTEGER;
- result := 1 + storage.fast_index_of (ch,1) until (count - 1);
- ? {(result != count + 1) ->> {item result = ch}};
+ result := 1 + storage.fast_index_of (ch,0) until (count - 1);
+ ? {(result != count + 1) ->> {item result = ch}};
result
);
+
+ - index_of ch:CHARACTER :INTEGER <-
+ // Gives the index of the first occurrence of 'ch' or
+ // 0 if none.
+ (
+ fast_index_of ch
+ );
- first_index_of c:CHARACTER :INTEGER <-
// Index of first occurrence of `c' at index 1 or after index 1.
diff --git a/lib/string/string.li b/lib/string/string.li
index 7ce665f..8723bac 100644
--- a/lib/string/string.li
+++ b/lib/string/string.li
@@ -25,7 +25,7 @@ Section Header
- copyright := "2003-2005 Jérome Boutet, 2003-2007 Benoit Sonntag";
- - comment := "String library.";
+ - comment := "String library. Strings are 1 based index.";
Section Inherit
diff --git a/lib/testing/unit_test.li b/lib/testing/unit_test.li
index 3d180aa..8cf3af6 100644
--- a/lib/testing/unit_test.li
+++ b/lib/testing/unit_test.li
@@ -190,7 +190,7 @@ Section Public
(got = expected).if {
test_passed name;
} else {
- //test_failed name got (got.to_string) expected (expected.to_string);
+ test_failed name got (got.to_string) expected (expected.to_string);
};
);
--
Lisaac compiler
More information about the Lisaac-commits
mailing list