Subversion Repositories HelenOS

Rev

Rev 4201 | Rev 4296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4201 Rev 4221
Line 197... Line 197...
197
    *offset += (1 + cbytes);
197
    *offset += (1 + cbytes);
198
   
198
   
199
    return true;
199
    return true;
200
}
200
}
201
 
201
 
202
/** Get bytes used by UTF-8 characters.
202
/** Get size of string, with length limit.
203
 *
203
 *
204
 * Get the number of bytes (count of plain characters) which
204
 * Get the number of bytes which are used by up to @a max_len first
205
 * are used by a given count of UTF-8 characters in a string.
205
 * characters in the string @a str. If @a max_len is greater than
206
 * As UTF-8 encoding is multibyte, there is no constant
206
 * the length of @a str, the entire string is measured.
207
 * correspondence between number of characters and used bytes.
-
 
208
 *
207
 *
209
 * @param str   UTF-8 string to consider.
208
 * @param str   String to consider.
210
 * @param count Number of UTF-8 characters to count.
209
 * @param count Maximum number of characters to measure.
211
 *
210
 *
212
 * @return Number of bytes used by the characters.
211
 * @return Number of bytes used by the characters.
213
 *
-
 
214
 */
212
 */
215
size_t utf8_count_bytes(const char *str, count_t count)
213
size_t str_lsize(const char *str, count_t max_len)
216
{
214
{
217
    size_t size = 0;
215
    count_t len = 0;
218
    index_t index = 0;
216
    size_t cur = 0;
219
    index_t iprev;
217
    size_t prev;
220
    wchar_t ch;
218
    wchar_t ch;
221
   
219
 
222
    while (true) {
220
    while (true) {
223
        iprev = index;
221
        prev = cur;
224
        if (size >= count)
222
        if (len >= max_len)
225
            break;
223
            break;
226
        ch = chr_decode(str, &index, UTF8_NO_LIMIT);
224
        ch = chr_decode(str, &cur, UTF8_NO_LIMIT);
227
        if (ch == '\0') break;
225
        if (ch == '\0') break;
228
 
226
 
229
        size++;
227
        len++;
230
    }
228
    }
231
   
229
 
232
    return iprev;
230
    return prev;
233
}
231
}
234
 
232
 
235
/** Check whether character is plain ASCII.
233
/** Check whether character is plain ASCII.
236
 *
234
 *
237
 * @return True if character is plain ASCII.
235
 * @return True if character is plain ASCII.
Line 260... Line 258...
260
 
258
 
261
/** Return number of plain characters in a string.
259
/** Return number of plain characters in a string.
262
 *
260
 *
263
 * @param str NULL-terminated string.
261
 * @param str NULL-terminated string.
264
 *
262
 *
265
 * @return Number of characters in str.
263
 * @return Number of characters in @a str.
266
 *
264
 *
267
 */
265
 */
268
size_t strlen(const char *str)
266
size_t strlen(const char *str)
269
{
267
{
270
    size_t size;
268
    size_t size;
271
    for (size = 0; str[size]; size++);
269
    for (size = 0; str[size]; size++);
272
   
270
   
273
    return size;
271
    return size;
274
}
272
}
275
 
273
 
276
/** Return number of UTF-8 characters in a string.
274
/** Return number of characters in a string.
277
 *
-
 
278
 * @param str NULL-terminated UTF-8 string.
-
 
279
 *
-
 
280
 * @return Number of UTF-8 characters in str.
-
 
281
 *
275
 *
-
 
276
 * @param str NULL-terminated string.
-
 
277
 * @return Number of characters in string.
282
 */
278
 */
283
size_t strlen_utf8(const char *str)
279
count_t str_length(const char *str)
284
{
280
{
285
    size_t size = 0;
281
    count_t len = 0;
286
    index_t index = 0;
282
    size_t offset = 0;
287
   
283
 
288
    while (chr_decode(str, &index, UTF8_NO_LIMIT) != 0) {
284
    while (chr_decode(str, &offset, UTF8_NO_LIMIT) != 0) {
289
        size++;
285
        len++;
290
    }
286
    }
291
   
287
 
292
    return size;
288
    return len;
293
}
289
}
294
 
290
 
295
/** Return number of UTF-32 characters in a string.
291
/** Return number of characters in a wide string.
296
 *
-
 
297
 * @param str NULL-terminated UTF-32 string.
-
 
298
 *
-
 
299
 * @return Number of UTF-32 characters in str.
-
 
300
 *
292
 *
-
 
293
 * @param str NULL-terminated wide string.
-
 
294
 * @return Number of characters in @a str.
301
 */
295
 */
302
size_t strlen_utf32(const wchar_t *str)
296
count_t wstr_length(const wchar_t *wstr)
303
{
297
{
304
    size_t size;
298
    count_t len;
-
 
299
 
-
 
300
    len = 0;
305
    for (size = 0; str[size]; size++);
301
    while (*wstr++ != '\0')
-
 
302
        ++len;
306
   
303
 
307
    return size;
304
    return len;
308
}
305
}
309
 
306
 
310
/** Compare two NULL terminated strings
307
/** Compare two NULL terminated strings
311
 *
308
 *
312
 * Do a char-by-char comparison of two NULL terminated strings.
309
 * Do a char-by-char comparison of two NULL terminated strings.