summaryrefslogtreecommitdiff
path: root/src/common/strlib.h
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-09 22:08:31 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-09 22:08:31 +0000
commitb83d9633d70ee986fa52cf0445c228190ddf0b13 (patch)
treea50f200e4a322fc92decd9ef4537077b087fb109 /src/common/strlib.h
parentfa26ed23b8bb0ae3eeca8a916930d0a8053d3a41 (diff)
downloadhercules-b83d9633d70ee986fa52cf0445c228190ddf0b13.tar.gz
hercules-b83d9633d70ee986fa52cf0445c228190ddf0b13.tar.bz2
hercules-b83d9633d70ee986fa52cf0445c228190ddf0b13.tar.xz
hercules-b83d9633d70ee986fa52cf0445c228190ddf0b13.zip
* Added a generic 'delimiter-separated values' string parser to strlib.c/h.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11878 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/strlib.h')
-rw-r--r--src/common/strlib.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/common/strlib.h b/src/common/strlib.h
index 31e364e2a..d1fb20d49 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -46,6 +46,42 @@ int safesnprintf(char* buf, size_t sz, const char* fmt, ...);
/// Lines start at 1.
int strline(const char* str, size_t pos);
+
+
+/// Bitfield determining the behaviour of sv_parse.
+enum e_svopt
+{
+ // default: no escapes and no line terminator
+ SV_NOESCAPE_NOTERMINATE = 0,
+ // Escapes according to the C compiler.
+ SV_ESCAPE_C = 1,
+ // Line terminators
+ SV_TERMINATE_LF = 2,
+ SV_TERMINATE_CRLF = 4,
+ SV_TERMINATE_CR = 8,
+};
+
+/// Other escape sequences supported by the C compiler.
+#define SV_ESCAPE_C_SUPPORTED "abtnvfr\?\"'\\"
+
+/// Parses a delim-separated string.
+/// Starts parsing at startoff and fills the pos array with the start and end
+/// positions in the string of the line and fields (that fit the array).
+/// Returns the number of fields or -1 if an error occurs.
+int sv_parse(const char* str, int len, int startoff, char delim, int* out_pos, int npos, enum e_svopt opt);
+
+/// Escapes src to out_dest according to the format of the C compiler.
+/// Returns the length of the escaped string.
+/// out_dest should be len*4+1 in size.
+size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* escapes);
+
+/// Unescapes src to out_dest according to the format of the C compiler.
+/// Returns the length of the unescaped string.
+/// out_dest should be len+1 in size and can be the same buffer as src.
+size_t sv_unescape_c(char* out_dest, const char* src, size_t len);
+
+
+
/// StringBuf - dynamic string
struct StringBuf
{