guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, master, updated. release_1-9-12-13-gcf


From: Michael Gran
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-12-13-gcf313a9
Date: Sun, 12 Sep 2010 15:31:53 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=cf313a947b56cef3b3f3bc08ced70b9bba44d681

The branch, master has been updated
       via  cf313a947b56cef3b3f3bc08ced70b9bba44d681 (commit)
      from  58228cc689c51d025588abd8de3d8dbf44851369 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cf313a947b56cef3b3f3bc08ced70b9bba44d681
Author: Michael Gran <address@hidden>
Date:   Sun Sep 12 08:29:31 2010 -0700

    Provide non-locale C/Scheme string conversion functions
    
    * doc/ref/api-data.texi: document scm_to_stringn, scm_from_stringn,
      scm_to_latin1_stringn, and scm_from_latin1_stringn
    * libguile/strings.h (scm_to_stringn): make public
      (scm_to_latin1_stringn): new declaration
      (scm_from_latin1_stringn): new declaration
    * libguile/strings.c (scm_to_latin1_stringn): new function
      (scm_from_latin1_stringn): new function

-----------------------------------------------------------------------

Summary of changes:
 doc/ref/api-data.texi |   68 +++++++++++++++++++++++++++++++++++++++++++++++++
 libguile/strings.c    |   11 ++++++++
 libguile/strings.h    |   16 ++++++------
 3 files changed, 87 insertions(+), 8 deletions(-)

diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index 75e5e68..82982e9 100755
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -3969,6 +3969,74 @@ is larger than @var{max_len}, only @var{max_len} bytes 
have been
 stored and you probably need to try again with a larger buffer.
 @end deftypefn
 
+For most situations, string conversion should occur using the current
+locale, such as with the functions above.  But there may be cases where
+one wants to convert strings from a character encoding other than the
+locale's character encoding.  For these cases, the lower-level functions
address@hidden and @code{scm_from_stringn} are provided.  These
+functions should seldom be necessary if one is properly using locales.
+
address@hidden {C Type} scm_t_string_failed_conversion_handler
+This is an enumerated type that can take one of three values:
address@hidden,
address@hidden, and
address@hidden  They are used to indicate
+a strategy for handling characters that cannot be converted to or from a
+given character encoding.  @code{SCM_FAILED_CONVERSION_ERROR} indicates
+that a conversion should throw an error if some characters cannot be
+converted.  @code{SCM_FAILED_CONVERSION_QUESTION_MARK} indicates that a
+conversion should replace unconvertable characters with the question
+mark character.  And, @code{SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE}
+requests that a conversion should replace an unconvertable character
+with an escape sequence.
+
+While all three strategies apply when converting Scheme strings to C,
+only @code{SCM_FAILED_CONVERSION_ERROR} and
address@hidden can be used when converting C
+strings to Scheme.
address@hidden deftp
+
address@hidden {C Function} char *scm_to_stringn (SCM str, size_t *lenp, const 
char *encoding, scm_t_string_failed_conversion_handler handler)
+This function returns a newly allocated C string from the Guile string
address@hidden  The length of the string will be returned in @var{lenp}.
+The character encoding of the C string is passed as the ASCII,
+null-terminated C string @var{encoding}.  The @var{handler} parameter
+gives a strategy for dealing with characters that cannot be converted
+into @var{encoding}.
+
+If @var{lenp} is NULL, this function will return a null-terminated C
+string.  It will throw an error if the string contains a null
+character.
address@hidden deftypefn
+
address@hidden {C Function} SCM scm_from_stringn (const char *str, size_t len, 
const char *encoding, scm_t_string_failed_conversion_handler handler)
+This function returns a scheme string from the C string @var{str}.  The
+length of the C string is input as @var{len}.  The encoding of the C
+string is passed as the ASCII, null-terminated C string @code{encoding}.
+The @var{handler} parameters suggests a strategy for dealing with
+unconvertable characters.
address@hidden deftypefn
+
+ISO-8859-1 is the most common 8-bit character encoding.  This encoding
+is also referred to as the Latin-1 encoding.  The following two
+conversion functions are provided to convert between Latin-1 C strings
+and Guile strings.
+
address@hidden {C Function} SCM scm_from_latin1_stringn (const char *str, 
size_t len)
+This function returns a scheme string from an ISO-8859-1-encoded C
+string @var{str} of length @var{len}.
address@hidden deftypefn
+
address@hidden {C function} char * scm_to_latin1_stringn (SCM str, size_t *lenp)
+This function returns a newly allocated, ISO-8859-1-encoded C string
+from the scheme string @var{str}.  An error will be thrown if the scheme
+string cannot be converted to the ISO-8859-1 encoding.  If @var{lenp} is
address@hidden, the returned C string will be null terminated, and an error
+will be thrown if the C string would otherwise contain null
+characters. If @var{lenp} is not NULL, the length of the string is
+returned in @var{lenp}, and the string is not null terminated.
address@hidden deftypefn
+
 @node String Internals
 @subsubsection String Internals
 
diff --git a/libguile/strings.c b/libguile/strings.c
index 52dfb53..68fa25c 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -1502,6 +1502,12 @@ scm_from_stringn (const char *str, size_t len, const 
char *encoding,
 }
 
 SCM
+scm_from_latin1_stringn (const char *str, size_t len)
+{
+  return scm_from_stringn (str, len, NULL, SCM_FAILED_CONVERSION_ERROR);
+}
+
+SCM
 scm_from_locale_stringn (const char *str, size_t len)
 {
   const char *enc;
@@ -1697,6 +1703,11 @@ unistring_escapes_to_r6rs_escapes (char **bufp, size_t 
*lenp)
   memcpy (before, after, j);
 }
 
+char *
+scm_to_latin1_stringn (SCM str, size_t *lenp)
+{
+  return scm_to_stringn (str, lenp, NULL, SCM_FAILED_CONVERSION_ERROR);
+}
 
 char *
 scm_to_locale_stringn (SCM str, size_t *lenp)
diff --git a/libguile/strings.h b/libguile/strings.h
index 734ac62..4b120e0 100644
--- a/libguile/strings.h
+++ b/libguile/strings.h
@@ -113,10 +113,8 @@ SCM_API SCM scm_substring_shared (SCM str, SCM start, SCM 
end);
 SCM_API SCM scm_substring_copy (SCM str, SCM start, SCM end);
 SCM_API SCM scm_string_append (SCM args);
 
-SCM_API SCM scm_from_stringn (const char *str, size_t len, 
-                                     const char *encoding,
-                                     scm_t_string_failed_conversion_handler 
-                                     handler);
+SCM_API SCM scm_from_stringn (const char *str, size_t len, const char 
*encoding,
+                              scm_t_string_failed_conversion_handler handler);
 SCM_API SCM scm_c_make_string (size_t len, SCM chr);
 SCM_API size_t scm_c_string_length (SCM str);
 SCM_API size_t scm_c_symbol_length (SCM sym);
@@ -128,17 +126,17 @@ SCM_API SCM scm_c_substring_shared (SCM str, size_t 
start, size_t end);
 SCM_API SCM scm_c_substring_copy (SCM str, size_t start, size_t end);
 
 SCM_API int scm_is_string (SCM x);
+SCM_API SCM scm_from_latin1_stringn (const char *str, size_t len);
 SCM_API SCM scm_from_locale_string (const char *str);
 SCM_API SCM scm_from_locale_stringn (const char *str, size_t len);
 SCM_INTERNAL SCM scm_i_from_utf8_string (const scm_t_uint8 *str);
 SCM_API SCM scm_take_locale_string (char *str);
 SCM_API SCM scm_take_locale_stringn (char *str, size_t len);
+SCM_API char *scm_to_latin1_stringn (SCM str, size_t *lenp);
 SCM_API char *scm_to_locale_string (SCM str);
 SCM_API char *scm_to_locale_stringn (SCM str, size_t *lenp);
-SCM_INTERNAL char *scm_to_stringn (SCM str, size_t *lenp, 
-                                   const char *encoding,
-                                   scm_t_string_failed_conversion_handler
-                                   handler);
+SCM_API char *scm_to_stringn (SCM str, size_t *lenp, const char *encoding,
+                              scm_t_string_failed_conversion_handler handler);
 SCM_INTERNAL scm_t_uint8 *scm_i_to_utf8_string (SCM str);
 SCM_API size_t scm_to_locale_stringbuf (SCM str, char *buf, size_t max_len);
 
@@ -215,6 +213,8 @@ SCM_API SCM scm_sys_symbol_dump (SCM);
 SCM_API SCM scm_sys_stringbuf_hist (void);
 #endif
 
+
+
 /* deprecated stuff */
 
 #if SCM_ENABLE_DEPRECATED


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]