diff options
| author | Lennart Poettering <lennart@poettering.net> | 2009-02-04 17:11:56 +0100 | 
|---|---|---|
| committer | Lennart Poettering <lennart@poettering.net> | 2009-02-04 17:11:56 +0100 | 
| commit | 0fc59e4585937b155125ef01b0e8c2ae9e5f6cee (patch) | |
| tree | 12f8c48f96be1f1b70ff77b41f0995188992e1b9 /src | |
| parent | ce76216bce9981c31ebab2ca5a97d6c5c0509edd (diff) | |
add new API pa_ascii_valid(), pa_ascii_filter()
Diffstat (limited to 'src')
| -rw-r--r-- | src/map-file | 2 | ||||
| -rw-r--r-- | src/pulse/utf8.c | 26 | ||||
| -rw-r--r-- | src/pulse/utf8.h | 6 | 
3 files changed, 34 insertions, 0 deletions
| diff --git a/src/map-file b/src/map-file index cdb9debe..ca4e7a72 100644 --- a/src/map-file +++ b/src/map-file @@ -1,5 +1,7 @@  PULSE_0 {  global: +pa_ascii_filter; +pa_ascii_valid;  pa_browser_new;  pa_browser_new_full;  pa_browser_ref; diff --git a/src/pulse/utf8.c b/src/pulse/utf8.c index 7671be46..6b58bde3 100644 --- a/src/pulse/utf8.c +++ b/src/pulse/utf8.c @@ -263,3 +263,29 @@ char* pa_locale_to_utf8 (const char *str) {  }  #endif + +char *pa_ascii_valid(const char *str) { +    const char *p; +    pa_assert(str); + +    for (p = str; *p; p++) +        if ((unsigned char) *p >= 128) +            return NULL; + +    return (char*) str; +} + +char *pa_ascii_filter(const char *str) { +    char *r, *s, *d; +    pa_assert(str); + +    r = pa_xstrdup(str); + +    for (s = r, d = r; *s; s++) +        if ((unsigned char) *s < 128) +            *(d++) = *s; + +    *d = 0; + +    return r; +} diff --git a/src/pulse/utf8.h b/src/pulse/utf8.h index 4d751953..b9f74952 100644 --- a/src/pulse/utf8.h +++ b/src/pulse/utf8.h @@ -36,9 +36,15 @@ PA_C_DECL_BEGIN  /** Test if the specified strings qualifies as valid UTF8. Return the string if so, otherwise NULL */  char *pa_utf8_valid(const char *str) PA_GCC_PURE; +/** Test if the specified strings qualifies as valid 7-bit ASCII. Return the string if so, otherwise NULL. \since 0.9.15 */ +char *pa_ascii_valid(const char *str) PA_GCC_PURE; +  /** Filter all invalid UTF8 characters from the specified string, returning a new fully UTF8 valid string. Don't forget to free the returned string with pa_xfree() */  char *pa_utf8_filter(const char *str); +/** Filter all invalid ASCII characters from the specified string, returning a new fully ASCII valid string. Don't forget to free the returned string with pa_xfree(). \since 0.9.15 */ +char *pa_ascii_filter(const char *str); +  /** Convert a UTF-8 string to the current locale. Free the string using pa_xfree(). */  char* pa_utf8_to_locale (const char *str); | 
