LRN: add function GNUNET_STRINGS_get_short_name to get basename
[oweals/gnunet.git] / src / include / gnunet_strings_lib.h
index dd78aee35c1156734973f41baaa77455c57fbb0a..8101a8113d262e1b4a88366ea7d737ca78877c63 100644 (file)
@@ -50,15 +50,53 @@ extern "C"
 #include "gnunet_time_lib.h"
 
 
+/**
+ * Convert a given fancy human-readable size to bytes.
+ *
+ * @param fancy_size human readable string (i.e. 1 MB)
+ * @param size set to the size in bytes
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
+                                    unsigned long long *size);
+
+
+/**
+ * Convert a given fancy human-readable time to our internal
+ * representation.
+ *
+ * @param fancy_size human readable string (i.e. 1 minute)
+ * @param rtime set to the relative time
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size,
+                                       struct GNUNET_TIME_Relative *rtime);
+
+
 /**
  * Convert a given filesize into a fancy human-readable format.
  *
  * @param size number of bytes
  * @return fancy representation of the size (possibly rounded) for humans
  */
-char *GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
+char *
+GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
 
 
+/**
+ * Convert the len characters long character sequence
+ * given in input that is in the given input charset
+ * to a string in given output charset.
+ * @return the converted string (0-terminated),
+ *  if conversion fails, a copy of the orignal
+ *  string is returned.
+ */
+char *
+GNUNET_STRINGS_conv (const char *input, size_t len,
+    const char *input_charset, const char *output_charset);
+
 /**
  * Convert the len characters long character sequence
  * given in input that is in the given charset
@@ -69,8 +107,19 @@ char *GNUNET_STRINGS_byte_size_fancy (unsigned long long size);
  * @param charset character set to convert from
  * @return the converted string (0-terminated)
  */
-char *GNUNET_STRINGS_to_utf8 (const char *input, size_t len,
-                              const char *charset);
+char *
+GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset);
+
+/**
+ * Convert the len bytes-long UTF-8 string
+ * given in input to the given charset.
+
+ * @return the converted string (0-terminated),
+ *  if conversion fails, a copy of the orignal
+ *  string is returned.
+ */
+char *
+GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset);
 
 
 /**
@@ -81,7 +130,9 @@ char *GNUNET_STRINGS_to_utf8 (const char *input, size_t len,
  * @return the full file name,
  *          NULL is returned on error
  */
-char *GNUNET_STRINGS_filename_expand (const char *fil);
+char *
+GNUNET_STRINGS_filename_expand (const char *fil);
+
 
 /**
  * Fill a buffer of the given size with
@@ -104,8 +155,8 @@ char *GNUNET_STRINGS_filename_expand (const char *fil);
  * @return number of bytes written to the buffer
  *         (or number of bytes that would have been written)
  */
-size_t GNUNET_STRINGS_buffer_fill (char *buffer, size_t size,
-                                   unsigned int count, ...);
+size_t
+GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...);
 
 
 /**
@@ -122,8 +173,9 @@ size_t GNUNET_STRINGS_buffer_fill (char *buffer, size_t size,
  * @return offset of the character after the last 0-termination
  *         in the buffer, or 0 on error.
  */
-unsigned int GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
-                                             unsigned int count, ...);
+unsigned int
+GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
+                                unsigned int count, ...);
 
 
 
@@ -134,7 +186,8 @@ unsigned int GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
  * @param t the absolute time to convert
  * @return timestamp in human-readable form
  */
-char *GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t);
+char *
+GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t);
 
 
 /**
@@ -143,8 +196,22 @@ char *GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t);
  * @param delta time in milli seconds
  * @return string in human-readable form
  */
-char *GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative
-                                              delta);
+char *
+GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta);
+
+/**
+ * "man basename"
+ * Returns a pointer to a part of filename (allocates nothing)!
+ *
+ * @param filename filename to extract basename from
+ * @return short (base) name of the file (that is, everything following the
+ *         last directory separator in filename. If filename ends with a
+ *         directory separator, the result will be a zero-length string.
+ *         If filename has no directory separators, the result is filename
+ *         itself.
+ */
+const char *
+GNUNET_STRINGS_get_short_name (const char *filename);
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {