Index: kernel/generic/src/lib/string.c
===================================================================
--- kernel/generic/src/lib/string.c	(revision b54d2f177d73478c2fc4d1d122eddfecc7393b6d)
+++ kernel/generic/src/lib/string.c	(revision e1813cf4114a4d3ec284d7ebb2533fb7ce78e6fd)
@@ -57,20 +57,20 @@
 #define CONT_BITS 6
 
-/** Decode a single UTF-8 character from a NULL-terminated string.
- *
- * Decode a single UTF-8 character from a plain char NULL-terminated
- * string. Decoding starts at @index and this index is moved to the
- * beginning of the next character. In case of decoding error,
- * index advances. However, index is never moved beyond (str+limit).
- *
- * @param str   Plain character NULL-terminated string.
+/** Decode a single character from a substring.
+ *
+ * Decode a single character from a substring of size @a sz. Decoding starts
+ * at @a offset and this offset is moved to the beginning of the next
+ * character. In case of decoding error, offset generally advances at least
+ * by one. However, offset is never moved beyond (str + sz).
+ *
+ * @param str   String (not necessarily NULL-terminated).
  * @param index Index (counted in plain characters) where to start
  *              the decoding.
- * @param limit Maximal allowed value of index.
- *
- * @return Decoded character in UTF-32 or '?' if the encoding is wrong.
- *
- */
-wchar_t utf8_decode(const char *str, index_t *index, index_t limit)
+ * @param limit Size of the substring.
+ *
+ * @return	Value of decoded character or '?' on decoding error.
+ *
+ */
+wchar_t chr_decode(const char *str, size_t *offset, size_t sz)
 {
 	uint8_t b0, b;          /* Bytes read from str. */
@@ -80,8 +80,8 @@
 	int cbytes;		/* Number of continuation bytes. */
 
-	if (*index + 1 > limit)
+	if (*offset + 1 > sz)
 		return invalch;
 
-	b0 = (uint8_t) str[(*index)++];
+	b0 = (uint8_t) str[(*offset)++];
 
 	/* Determine code length. */
@@ -108,5 +108,5 @@
 	}
 
-	if (*index + cbytes > limit) {
+	if (*offset + cbytes > sz) {
 		return invalch;
 	}
@@ -116,5 +116,5 @@
 	/* Decode continuation bytes. */
 	while (cbytes > 0) {
-		b = (uint8_t) str[(*index)++];
+		b = (uint8_t) str[(*offset)++];
 
 		/* Must be 10xxxxxx. */
@@ -131,23 +131,20 @@
 }
 
-/** Encode a single UTF-32 character as UTF-8
- *
- * Encode a single UTF-32 character as UTF-8 and store it into
- * the given buffer at @index. Encoding starts at @index and
- * this index is moved at the position where the next character
- * can be written to.
- *
- * @param ch    Input UTF-32 character.
- * @param str   Output buffer.
- * @param index Index (counted in plain characters) where to start
- *              the encoding
- * @param limit Maximal allowed value of index.
- *
- * @return True if the character was encoded or false if there is not
- *         enought space in the output buffer or the character is invalid
- *         Unicode code point.
- *
- */
-bool utf8_encode(const wchar_t ch, char *str, index_t *index, index_t limit)
+/** Encode a single character to string representation.
+ *
+ * Encode a single character to string representation (i.e. UTF-8) and store
+ * it into a buffer at @a offset. Encoding starts at @a offset and this offset
+ * is moved to the position where the next character can be written to.
+ *
+ * @param ch		Input character.
+ * @param str		Output buffer.
+ * @param offset	Offset (in bytes) where to start writing.
+ * @param sz		Size of the output buffer.
+ *
+ * @return True if the character was encoded successfully or false if there
+ *	   was not enough space in the output buffer or the character code
+ *	   was invalid.
+ */
+bool chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz)
 {
 	uint32_t cc;		/* Unsigned version of ch. */
@@ -157,5 +154,5 @@
 	int i;
 
-	if (*index >= limit)
+	if (*offset >= sz)
 		return false;
 
@@ -185,18 +182,18 @@
 
 	/* Check for available space in buffer. */
-	if (*index + cbytes >= limit)
+	if (*offset + cbytes >= sz)
 		return false;
 
 	/* Encode continuation bytes. */
 	for (i = cbytes; i > 0; --i) {
-		str[*index + i] = 0x80 | (cc & LO_MASK_32(CONT_BITS));
+		str[*offset + i] = 0x80 | (cc & LO_MASK_32(CONT_BITS));
 		cc = cc >> CONT_BITS;
 	}
 
 	/* Encode first byte. */
-	str[*index] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
-
-	/* Advance index. */
-	*index += (1 + cbytes);
+	str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
+
+	/* Advance offset. */
+	*offset += (1 + cbytes);
 	
 	return true;
@@ -227,5 +224,5 @@
 		if (size >= count)
 			break;
-		ch = utf8_decode(str, &index, UTF8_NO_LIMIT);
+		ch = chr_decode(str, &index, UTF8_NO_LIMIT);
 		if (ch == '\0') break;
 
@@ -289,5 +286,5 @@
 	index_t index = 0;
 	
-	while (utf8_decode(str, &index, UTF8_NO_LIMIT) != 0) {
+	while (chr_decode(str, &index, UTF8_NO_LIMIT) != 0) {
 		size++;
 	}
