Subversion Repositories HelenOS

Rev

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

Rev 4223 Rev 4224
Line 456... Line 456...
456
 *         1 if second smaller.
456
 *         1 if second smaller.
457
 *
457
 *
458
 */
458
 */
459
int str_cmp(const char *s1, const char *s2)
459
int str_cmp(const char *s1, const char *s2)
460
{
460
{
461
    wchar_t c1;
461
    wchar_t c1 = 0;
462
    wchar_t c2;
462
    wchar_t c2 = 0;
463
   
463
   
464
    size_t off1 = 0;
464
    size_t off1 = 0;
465
    size_t off2 = 0;
465
    size_t off2 = 0;
466
   
466
 
-
 
467
    while (true) {
467
    while ((c1 = str_decode(s1, &off1, STR_NO_LIMIT) != 0)
468
        c1 = str_decode(s1, &off1, STR_NO_LIMIT);
468
        && (c2 = str_decode(s2, &off2, STR_NO_LIMIT) != 0)) {
469
        c2 = str_decode(s2, &off2, STR_NO_LIMIT);
469
       
-
 
470
        if (off1 != off2)
-
 
471
            break;
-
 
472
       
470
 
473
        if (c1 < c2)
471
        if (c1 < c2)
474
            return -1;
472
            return -1;
475
       
473
       
476
        if (c1 > c2)
474
        if (c1 > c2)
477
            return 1;
475
            return 1;
-
 
476
 
-
 
477
        if (c1 == 0 || c2 == 0)
-
 
478
            break;     
478
    }
479
    }
479
   
480
 
480
    if ((off1 == off2) && (c1 == c2))
-
 
481
        return 0;
481
    return 0;
482
   
-
 
483
    if ((c1 == 0) || (off1 < off2))
-
 
484
        return -1;
-
 
485
   
-
 
486
    return 1;
-
 
487
}
482
}
488
 
483
 
489
/** Compare two NULL terminated strings with length limit.
484
/** Compare two NULL terminated strings with length limit.
490
 *
485
 *
491
 * Do a char-by-char comparison of two NULL-terminated strings.
486
 * Do a char-by-char comparison of two NULL-terminated strings.
Line 507... Line 502...
507
   
502
   
508
    size_t off1 = 0;
503
    size_t off1 = 0;
509
    size_t off2 = 0;
504
    size_t off2 = 0;
510
   
505
   
511
    count_t len = 0;
506
    count_t len = 0;
512
   
507
 
513
    while ((len < max_len)
508
    while (true) {
514
        && ((c1 = str_decode(s1, &off1, STR_NO_LIMIT)) != 0)
-
 
515
        && ((c2 = str_decode(s2, &off2, STR_NO_LIMIT)) != 0)) {
-
 
516
       
-
 
517
        if (off1 != off2)
509
        if (len >= max_len)
518
            break;
510
            break;
-
 
511
 
-
 
512
        c1 = str_decode(s1, &off1, STR_NO_LIMIT);
-
 
513
        c2 = str_decode(s2, &off2, STR_NO_LIMIT);
519
       
514
 
520
        if (c1 < c2)
515
        if (c1 < c2)
521
            return -1;
516
            return -1;
522
       
517
 
523
        if (c1 > c2)
518
        if (c1 > c2)
524
            return 1;
519
            return 1;
-
 
520
 
-
 
521
        if (c1 == 0 || c2 == 0)
-
 
522
            break;
525
       
523
 
526
        len++;
524
        ++len; 
527
    }
525
    }
528
   
526
 
529
    if ((off1 == off2) && (len == max_len) && (c1 == c2))
-
 
530
        return 0;
527
    return 0;
531
   
528
 
532
    if ((c1 == 0) || (off1 < off2))
-
 
533
        return -1;
-
 
534
   
-
 
535
    return 1;
-
 
536
}
529
}
537
 
530
 
538
/** Copy NULL-terminated string.
531
/** Copy NULL-terminated string.
539
 *
532
 *
540
 * Copy source string @a src to destination buffer @a dst.
533
 * Copy source string @a src to destination buffer @a dst.
Line 556... Line 549...
556
   
549
   
557
    wchar_t ch;
550
    wchar_t ch;
558
    size_t str_off = 0;
551
    size_t str_off = 0;
559
    size_t dst_off = 0;
552
    size_t dst_off = 0;
560
   
553
   
561
    while ((ch = str_decode(src, &str_off, STR_NO_LIMIT) != 0)) {
554
    while ((ch = str_decode(src, &str_off, STR_NO_LIMIT)) != 0) {
562
        if (chr_encode(ch, dst, &dst_off, size) != EOK)
555
        if (chr_encode(ch, dst, &dst_off, size) != EOK)
563
            break;
556
            break;
564
    }
557
    }
565
   
558
   
566
    if (dst_off >= size)
559
    if (dst_off >= size)
Line 614... Line 607...
614
const char *str_chr(const char *str, wchar_t ch)
607
const char *str_chr(const char *str, wchar_t ch)
615
{
608
{
616
    wchar_t acc;
609
    wchar_t acc;
617
    size_t off = 0;
610
    size_t off = 0;
618
   
611
   
619
    while ((acc = str_decode(str, &off, STR_NO_LIMIT) != 0)) {
612
    while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
620
        if (acc == ch)
613
        if (acc == ch)
621
            return (str + off);
614
            return (str + off);
622
    }
615
    }
623
   
616
   
624
    return NULL;
617
    return NULL;