From Harald Welte:
[obnox/wireshark/wip.git] / epan / strutil.h
index 5e5eac1df4960d6bd9191935895c39f9d6616201..8c1dbcbc903b5cb0153ea30de1f5e887b4f7e4fd 100644 (file)
 #ifndef __STRUTIL_H__
 #define __STRUTIL_H__
 
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
 /* ... thus, config.h needs to be #included */
 
 /** @file
@@ -62,9 +66,20 @@ int        get_token_len(const guchar *linep, const guchar *lineend,
  *
  * @see tvb_format_text()
  */
-gchar*     format_text(const guchar *line, int len);
+gchar*     format_text(const guchar *line, size_t len);
 
-gchar*     format_text_wsp(const guchar *line, int len);
+/**
+ * Given a string, generate a string from it that shows non-printable
+ * characters as C-style escapes except a whitespace character
+ * (space, tab, carriage return, new line, vertical tab, or formfeed)
+ * which will be replaced by a space, and return a pointer to it.
+ *
+ * @param line A pointer to the input string
+ * @param len The length of the input string
+ * @return A pointer to the formatted string
+ *
+ */
+gchar*     format_text_wsp(const guchar *line, size_t len);
 
 /** Turn an array of bytes into a string showing the bytes in hex.
  *
@@ -141,7 +156,7 @@ gboolean   oid_str_to_bytes(const char *oid_str, GByteArray *bytes);
  * @param ba The byte array to be copied.
  * @return If ba exists, a freshly allocated copy.  NULL otherwise.
  *
- * XXX - Should this be in strutil.c?
+ * @todo - Should this be in strutil.c?
  */
 GByteArray *byte_array_dup(GByteArray *ba);
 
@@ -154,7 +169,7 @@ GByteArray *byte_array_dup(GByteArray *ba);
  *         their contents are equal, returns TRUE.  Otherwise, returns
  *         FALSE.
  *
- * XXX - Should this be in strutil.c?
+ * @todo - Should this be in strutil.c?
  */
 gboolean byte_array_equal(GByteArray *ba1, GByteArray *ba2);
 
@@ -182,7 +197,7 @@ gchar*     xml_escape(const gchar *unescaped);
 const guint8 * epan_memmem(const guint8 *haystack, guint haystack_len,
                const guint8 *needle, guint needle_len);
 
-/* Surround a string or a macro, resolved to a string, with double quotes */
+/** Surround a string or a macro, resolved to a string, with double quotes */
 #define _STRINGIFY(a)           # a
 #define STRINGIFY(a)            _STRINGIFY(a)
 
@@ -215,23 +230,50 @@ char * convert_string_case(const char *string, gboolean case_insensitive);
  */
 char * epan_strcasestr(const char *haystack, const char *needle);
 
-/* g_strlcat() does not exist in GLib 1.2[.x] */
-#if GLIB_MAJOR_VERSION < 2
-gsize g_strlcat(gchar *dst, gchar *src, gsize size);
-#endif
+/** Guarantee a non-null string.
+ *
+ * @param string The string to check
+ * @return A pointer 'string' if it's non-null, otherwise "[NULL]".
+ */
+const char * string_or_null(const char *string);
+
+int escape_string_len(const char *string);
+char * escape_string(char *dst, const char *string);
+
+
+void IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len);
+
+/** Copy a string, escaping the 'chr' characters in it
+ *
+ * @param str The string to be copied
+ * @param char The character to be escaped
+ * @return A copy of the string with every original 'chr' being
+ * transformed into double 'chr'.
+ */
+gchar* ws_strdup_escape_char (const gchar *str, const gchar chr);
+
+/** Copy a string, unescaping the 'chr' characters in it
+ *
+ * @param str The string to be copied
+ * @param char The character to be escaped
+ * @return A copy of the string with every occurence of double 'chr' in
+ * the original string being copied as a single 'chr'.
+ */
+gchar* ws_strdup_unescape_char (const gchar *str, const gchar chr);
 
-#if GLIB_MAJOR_VERSION < 2
-/* g_ascii_isprint() does not exist in GLib 1.2[.x].
- * assume all codes >=0x20 and <0x80 are ASCII printables.
+/** Replace values in a string
+ *
+ * @param str String containing 0 or more values to be replaced.
+ * @param old_val Old value.
+ * @param new_val New value. May be NULL, in which case occurences of
+ *                           old_value will be removed.
+ * @return A newly-allocated version of str with replacement values or
+ * NULL on failure.
  */
-#define g_ascii_isprint(c)                                             \
-       (((c<0x20)||(c>=0x80))?FALSE:TRUE)
-/* g_ascii_isxdigit() does not exist in Glib 1.2 */
-#define g_ascii_isxdigit(c)                                            \
-       ( ((c>='0')&&(c<='9'))?TRUE:                                    \
-               ( ((c>='a')&&(c<='f'))?TRUE:                            \
-                       (((c>='A')&&(c<='F'))?TRUE:FALSE) ) )
+gchar *string_replace(const gchar* str, const gchar *old_val, const gchar *new_val);
 
-#endif
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
 
 #endif /* __STRUTIL_H__ */