Changeset - r16663:6d591011eeb3
[Not reviewed]
master
0 2 0
rubidium - 14 years ago 2010-12-05 22:17:25
rubidium@openttd.org
(svn r21404) -Add: method for getting the length of an Utf8 string in characters
2 files changed with 17 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/string.cpp
Show inline comments
 
@@ -216,6 +216,21 @@ void str_strip_colours(char *str)
 
}
 

	
 
/**
 
 * Get the length of an UTF-8 encoded string in number of characters
 
 * and thus not the number of bytes that the encoded string contains.
 
 * @param s The string to get the length for.
 
 * @return The length of the string in characters.
 
 */
 
size_t Utf8StringLength(const char *s)
 
{
 
	size_t len = 0;
 
	const char *t = s;
 
	while (Utf8Consume(&t) != 0) len++;
 
	return len;
 
}
 

	
 

	
 
/**
 
 * Convert a given ASCII string to lowercase.
 
 * NOTE: only support ASCII characters, no UTF8 fancy. As currently
 
 * the function is only used to lowercase data-filenames if they are
src/string_func.h
Show inline comments
 
@@ -233,6 +233,8 @@ static inline char *Utf8PrevChar(char *s
 
	return ret;
 
}
 

	
 
size_t Utf8StringLength(const char *s);
 

	
 
/**
 
 * Is the given character a text direction character.
 
 * @param c The character to test.
0 comments (0 inline, 0 general)