[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Error reporting fix for string case conversion procedures
From: |
Martin Grabmueller |
Subject: |
Error reporting fix for string case conversion procedures |
Date: |
Fri, 26 Jan 2001 00:37:45 +0100 |
Hi all,
[I thought I had sent this patch already, but it does not show up in
the archives, so I re-send it. Please ignore it if it's a dup]
Attached is a fix to strop.c similar to that for string>? and friends.
string-upcase reports `string-upcase!' as the procedure name on
errors. While fixing that, I also cleaned up the other conversion
functions (they are also a bit faster because arguments are never
checked twice now ;-)
Regards,
'Martin
--
Martin Grabmueller address@hidden
http://www.pintus.de/mgrabmue/ address@hidden on EFnet
===File ~/cvs/guile-core/libguile/diff-strop================
Index: strop.c
===================================================================
RCS file: /cvs/guile/guile-core/libguile/strop.c,v
retrieving revision 1.48
diff -u -r1.48 strop.c
--- strop.c 2000/11/28 18:22:23 1.48
+++ strop.c 2001/01/25 23:32:54
@@ -330,6 +330,14 @@
#undef FUNC_NAME
+/* Helper function for the string copy and string conversion functions.
+ * No argument checking is performed. */
+static SCM
+string_copy (SCM str)
+{
+ return scm_makfromstr (SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str), 0);
+}
+
SCM_DEFINE (scm_string_copy, "string-copy", 1, 0, 0,
(SCM str),
@@ -337,7 +345,7 @@
#define FUNC_NAME s_scm_string_copy
{
SCM_VALIDATE_STRING (1, str);
- return scm_makfromstr (SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str), 0);
+ return string_copy (str);
}
#undef FUNC_NAME
@@ -357,8 +365,23 @@
}
#undef FUNC_NAME
+
+/* Helper function for the string uppercase conversion functions.
+ * No argument checking is performed. */
+static SCM
+string_upcase_x (SCM v)
+{
+ unsigned long k;
+
+ for (k = 0; k < SCM_STRING_LENGTH (v); ++k)
+ SCM_STRING_UCHARS (v) [k] = scm_upcase (SCM_STRING_UCHARS (v) [k]);
+
+ return v;
+}
+
+
SCM_DEFINE (scm_string_upcase_x, "string-upcase!", 1, 0, 0,
- (SCM v),
+ (SCM str),
"Destructively upcase every character in @code{str}.\n\n"
"(qdocs:) Converts each element in @var{str} to upper case.\n\n"
"@example\n"
@@ -369,14 +392,9 @@
"@end example")
#define FUNC_NAME s_scm_string_upcase_x
{
- unsigned long k;
-
- SCM_VALIDATE_STRING (1, v);
-
- for (k = 0; k < SCM_STRING_LENGTH (v); ++k)
- SCM_STRING_UCHARS (v) [k] = scm_upcase (SCM_STRING_UCHARS (v) [k]);
+ SCM_VALIDATE_STRING (1, str);
- return v;
+ return string_upcase_x (str);
}
#undef FUNC_NAME
@@ -385,12 +403,29 @@
"Upcase every character in @code{str}.")
#define FUNC_NAME s_scm_string_upcase
{
- return scm_string_upcase_x(scm_string_copy(str));
+ SCM_VALIDATE_STRING (1, str);
+
+ return string_upcase_x(string_copy(str));
}
#undef FUNC_NAME
+
+/* Helper function for the string lowercase conversion functions.
+ * No argument checking is performed. */
+static SCM
+string_downcase_x (SCM v)
+{
+ unsigned long k;
+
+ for (k = 0; k < SCM_STRING_LENGTH (v); ++k)
+ SCM_STRING_UCHARS (v) [k] = scm_downcase (SCM_STRING_UCHARS (v) [k]);
+
+ return v;
+}
+
+
SCM_DEFINE (scm_string_downcase_x, "string-downcase!", 1, 0, 0,
- (SCM v),
+ (SCM str),
"Destructively downcase every character in @code{str}.\n\n"
"(qdocs:) Converts each element in @var{str} to lower case.\n\n"
"@example\n"
@@ -403,14 +438,9 @@
"@end example")
#define FUNC_NAME s_scm_string_downcase_x
{
- unsigned long k;
-
- SCM_VALIDATE_STRING (1, v);
-
- for (k = 0; k < SCM_STRING_LENGTH (v); ++k)
- SCM_STRING_UCHARS (v) [k] = scm_downcase (SCM_STRING_UCHARS (v) [k]);
+ SCM_VALIDATE_STRING (1, str);
- return v;
+ return string_downcase_x (str);
}
#undef FUNC_NAME
@@ -420,18 +450,20 @@
#define FUNC_NAME s_scm_string_downcase
{
SCM_VALIDATE_STRING (1,str);
- return scm_string_downcase_x(scm_string_copy(str));
+
+ return string_downcase_x(string_copy(str));
}
#undef FUNC_NAME
-SCM_DEFINE (scm_string_capitalize_x, "string-capitalize!", 1, 0, 0,
- (SCM str),
- "Destructively capitalize every character in @code{str}.")
-#define FUNC_NAME s_scm_string_capitalize_x
+
+/* Helper function for the string capitalization functions.
+ * No argument checking is performed. */
+static SCM
+string_capitalize_x (SCM str)
{
char *sz;
int i, len, in_word=0;
- SCM_VALIDATE_STRING (1,str);
+
len = SCM_STRING_LENGTH(str);
sz = SCM_STRING_CHARS (str);
for(i=0; i<len; i++) {
@@ -447,6 +479,17 @@
}
return str;
}
+
+
+SCM_DEFINE (scm_string_capitalize_x, "string-capitalize!", 1, 0, 0,
+ (SCM str),
+ "Destructively capitalize every character in @code{str}.")
+#define FUNC_NAME s_scm_string_capitalize_x
+{
+ SCM_VALIDATE_STRING (1,str);
+
+ return string_capitalize_x (str);
+}
#undef FUNC_NAME
SCM_DEFINE (scm_string_capitalize, "string-capitalize", 1, 0, 0,
@@ -455,7 +498,8 @@
#define FUNC_NAME s_scm_string_capitalize
{
SCM_VALIDATE_STRING (1,str);
- return scm_string_capitalize_x(scm_string_copy(str));
+
+ return string_capitalize_x(string_copy(str));
}
#undef FUNC_NAME
============================================================
- Error reporting fix for string case conversion procedures,
Martin Grabmueller <=