summaryrefslogtreecommitdiffstats
path: root/include/import/ist.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/import/ist.h')
-rw-r--r--include/import/ist.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/import/ist.h b/include/import/ist.h
index e4e1425..962d63b 100644
--- a/include/import/ist.h
+++ b/include/import/ist.h
@@ -331,6 +331,25 @@ static inline struct ist istzero(const struct ist ist, size_t size)
return ret;
}
+/* Remove trailing newline characters if present in <ist> by reducing its
+ * length. Both '\n', '\r' and '\n\r' match. Return the modified ist.
+ */
+static inline struct ist iststrip(const struct ist ist)
+{
+ struct ist ret = ist;
+
+ if (ret.len) {
+ if (ret.ptr[ret.len - 1] == '\n')
+ --ret.len;
+ }
+ if (ret.len) {
+ if (ret.ptr[ret.len - 1] == '\r')
+ --ret.len;
+ }
+
+ return ret;
+}
+
/* returns the ordinal difference between two strings :
* < 0 if ist1 < ist2
* = 0 if ist1 == ist2