summaryrefslogtreecommitdiff
path: root/src/string.h
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2007-03-05 00:34:48 +0000
committerDarkvater <darkvater@openttd.org>2007-03-05 00:34:48 +0000
commitaea64adbb9ff755be303515bebb428d92e7bcc92 (patch)
tree42989af9a9c11fccbcbc9e6a9a9916bfbde95d8e /src/string.h
parentb3f59814de1a2dd94fcf97e63d33f85c621abe68 (diff)
downloadopenttd-aea64adbb9ff755be303515bebb428d92e7bcc92.tar.xz
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Diffstat (limited to 'src/string.h')
-rw-r--r--src/string.h26
1 files changed, 9 insertions, 17 deletions
diff --git a/src/string.h b/src/string.h
index da07f08d5..8b6d6792f 100644
--- a/src/string.h
+++ b/src/string.h
@@ -107,25 +107,17 @@ static inline bool IsUtf8Part(char c)
}
/**
- * Retrieve the (partial) length of the previous UNICODE character
- * in an UTF-8 encoded string.
- * @param s char pointer pointing to the first char of the next character
- * @returns the decoded length in bytes (size) of the UNICODE character
- * that was just before the one where 's' is pointing to
- * @note If 's' is not pointing to the first byte of the next UNICODE character
- * only a partial length of the sequence will be returned.
- * For example given this sequence: 0xE3 0x85 0x80, 0xE3 0x81 0x9E
- * 1. 's' is pointing to the second 0xE3, return value is 3
- * 2. 's' is pointing to 0x80, return value is 2.
- * So take care with the return values of this function. To get the real length
- * for an (invalid) sequence, pass the string offset of this function's return
- * value to Utf8EncodedCharLen() or Utf8Decode()
+ * Retrieve the previous UNICODE character in an UTF-8 encoded string.
+ * @param s char pointer pointing to (the first char of) the next character
+ * @returns a pointer in 's' to the previous UNICODE character's first byte
+ * @note The function should not be used to determine the length of the previous
+ * encoded char because it might be an invalid/corrupt start-sequence
*/
-static inline size_t Utf8PrevCharLen(const char *s)
+static inline char *Utf8PrevChar(const char *s)
{
- size_t len = 1;
- while (IsUtf8Part(*--s)) len++;
- return len;
+ const char *ret = s;
+ while (IsUtf8Part(*--ret));
+ return (char*)ret;
}