|
@@ -524,13 +524,14 @@ char *faux_str_casestr(const char *haystack, const char *needle)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-/** Prepare string for embedding to C-code (make escaping).
|
|
|
|
|
|
+/** Escape string.
|
|
*
|
|
*
|
|
* @warning The returned pointer must be freed by faux_str_free().
|
|
* @warning The returned pointer must be freed by faux_str_free().
|
|
* @param [in] src String for escaping.
|
|
* @param [in] src String for escaping.
|
|
|
|
+ * @param [in] escape_space Flag to escape spaces or not
|
|
* @return Escaped string or NULL on error.
|
|
* @return Escaped string or NULL on error.
|
|
*/
|
|
*/
|
|
-char *faux_str_c_esc(const char *src)
|
|
|
|
|
|
+static char *faux_str_c_esc_internal(const char *src, bool_t escape_space)
|
|
{
|
|
{
|
|
const char *src_ptr = src;
|
|
const char *src_ptr = src;
|
|
char *dst = NULL;
|
|
char *dst = NULL;
|
|
@@ -577,6 +578,12 @@ char *faux_str_c_esc(const char *src)
|
|
case '\t':
|
|
case '\t':
|
|
esc = "\\t";
|
|
esc = "\\t";
|
|
break;
|
|
break;
|
|
|
|
+ case ' ':
|
|
|
|
+ if (escape_space)
|
|
|
|
+ esc = "\\ ";
|
|
|
|
+ else
|
|
|
|
+ esc = " ";
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
// Check is the symbol control character. Control
|
|
// Check is the symbol control character. Control
|
|
// characters has codes from 0x00 to 0x1f.
|
|
// characters has codes from 0x00 to 0x1f.
|
|
@@ -605,6 +612,30 @@ char *faux_str_c_esc(const char *src)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+/** Prepare string for embedding to C-code (make escaping).
|
|
|
|
+ *
|
|
|
|
+ * @warning The returned pointer must be freed by faux_str_free().
|
|
|
|
+ * @param [in] src String for escaping.
|
|
|
|
+ * @return Escaped string or NULL on error.
|
|
|
|
+ */
|
|
|
|
+char *faux_str_c_esc(const char *src)
|
|
|
|
+{
|
|
|
|
+ return faux_str_c_esc_internal(src, BOOL_FALSE);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** Escaping string (escape spaces).
|
|
|
|
+ *
|
|
|
|
+ * @warning The returned pointer must be freed by faux_str_free().
|
|
|
|
+ * @param [in] src String for escaping.
|
|
|
|
+ * @return Escaped string or NULL on error.
|
|
|
|
+ */
|
|
|
|
+char *faux_str_c_esc_space(const char *src)
|
|
|
|
+{
|
|
|
|
+ return faux_str_c_esc_internal(src, BOOL_TRUE);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
/** Escape string and add quotes if necessary.
|
|
/** Escape string and add quotes if necessary.
|
|
*
|
|
*
|
|
* Quotes will be added if string contains spaces.
|
|
* Quotes will be added if string contains spaces.
|