root/lib/strutil/strutilascii.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. str_ascii_insert_replace_char
  2. str_ascii_is_valid_string
  3. str_ascii_is_valid_char
  4. str_ascii_cnext_char
  5. str_ascii_cprev_char
  6. str_ascii_cnext_noncomb_char
  7. str_ascii_cprev_noncomb_char
  8. str_ascii_isspace
  9. str_ascii_ispunct
  10. str_ascii_isalnum
  11. str_ascii_isdigit
  12. str_ascii_isprint
  13. str_ascii_iscombiningmark
  14. str_ascii_toupper
  15. str_ascii_tolower
  16. str_ascii_length
  17. str_ascii_length2
  18. str_ascii_conv_gerror_message
  19. str_ascii_vfs_convert_to
  20. str_ascii_term_form
  21. str_ascii_fit_to_term
  22. str_ascii_term_trim
  23. str_ascii_term_width2
  24. str_ascii_term_width1
  25. str_ascii_term_char_width
  26. str_ascii_term_substring
  27. str_ascii_trunc
  28. str_ascii_offset_to_pos
  29. str_ascii_column_to_pos
  30. str_ascii_create_search_needle
  31. str_ascii_release_search_needle
  32. str_ascii_search_first
  33. str_ascii_search_last
  34. str_ascii_compare
  35. str_ascii_ncompare
  36. str_ascii_casecmp
  37. str_ascii_ncasecmp
  38. str_ascii_fix_string
  39. str_ascii_create_key
  40. str_ascii_key_collate
  41. str_ascii_release_key
  42. str_ascii_prefix
  43. str_ascii_caseprefix
  44. str_ascii_init

   1 /*
   2    ASCII strings utilities
   3 
   4    Copyright (C) 2007-2024
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Rostislav Benes, 2007
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 #include <config.h>
  27 
  28 #include <ctype.h>
  29 #include <stdlib.h>
  30 
  31 #include "lib/global.h"
  32 #include "lib/strutil.h"
  33 
  34 /* using g_ascii function from glib
  35  * on terminal are showed only ascii characters (lower than 0x80)
  36  */
  37 
  38 /*** global variables ****************************************************************************/
  39 
  40 /*** file scope macro definitions ****************************************************************/
  41 
  42 /*** file scope type declarations ****************************************************************/
  43 
  44 /*** forward declarations (file scope functions) *************************************************/
  45 
  46 /*** file scope variables ************************************************************************/
  47 
  48 static const char replch = '?';
  49 
  50 /* --------------------------------------------------------------------------------------------- */
  51 /*** file scope functions ************************************************************************/
  52 /* --------------------------------------------------------------------------------------------- */
  53 
  54 static void
  55 str_ascii_insert_replace_char (GString *buffer)
     /* [previous][next][first][last][top][bottom][index][help]  */
  56 {
  57     g_string_append_c (buffer, replch);
  58 }
  59 
  60 /* --------------------------------------------------------------------------------------------- */
  61 
  62 static gboolean
  63 str_ascii_is_valid_string (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
  64 {
  65     (void) text;
  66     return TRUE;
  67 }
  68 
  69 /* --------------------------------------------------------------------------------------------- */
  70 
  71 static int
  72 str_ascii_is_valid_char (const char *ch, size_t size)
     /* [previous][next][first][last][top][bottom][index][help]  */
  73 {
  74     (void) ch;
  75     (void) size;
  76     return 1;
  77 }
  78 
  79 /* --------------------------------------------------------------------------------------------- */
  80 
  81 static void
  82 str_ascii_cnext_char (const char **text)
     /* [previous][next][first][last][top][bottom][index][help]  */
  83 {
  84     (*text)++;
  85 }
  86 
  87 /* --------------------------------------------------------------------------------------------- */
  88 
  89 static void
  90 str_ascii_cprev_char (const char **text)
     /* [previous][next][first][last][top][bottom][index][help]  */
  91 {
  92     (*text)--;
  93 }
  94 
  95 /* --------------------------------------------------------------------------------------------- */
  96 
  97 static int
  98 str_ascii_cnext_noncomb_char (const char **text)
     /* [previous][next][first][last][top][bottom][index][help]  */
  99 {
 100     if (*text[0] == '\0')
 101         return 0;
 102 
 103     (*text)++;
 104     return 1;
 105 }
 106 
 107 /* --------------------------------------------------------------------------------------------- */
 108 
 109 static int
 110 str_ascii_cprev_noncomb_char (const char **text, const char *begin)
     /* [previous][next][first][last][top][bottom][index][help]  */
 111 {
 112     if ((*text) == begin)
 113         return 0;
 114 
 115     (*text)--;
 116     return 1;
 117 }
 118 
 119 /* --------------------------------------------------------------------------------------------- */
 120 
 121 static gboolean
 122 str_ascii_isspace (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 123 {
 124     return g_ascii_isspace ((gchar) text[0]);
 125 }
 126 
 127 /* --------------------------------------------------------------------------------------------- */
 128 
 129 static gboolean
 130 str_ascii_ispunct (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 131 {
 132     return g_ascii_ispunct ((gchar) text[0]);
 133 }
 134 
 135 /* --------------------------------------------------------------------------------------------- */
 136 
 137 static gboolean
 138 str_ascii_isalnum (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 139 {
 140     return g_ascii_isalnum ((gchar) text[0]);
 141 }
 142 
 143 /* --------------------------------------------------------------------------------------------- */
 144 
 145 static gboolean
 146 str_ascii_isdigit (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 147 {
 148     return g_ascii_isdigit ((gchar) text[0]);
 149 }
 150 
 151 /* --------------------------------------------------------------------------------------------- */
 152 
 153 static gboolean
 154 str_ascii_isprint (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 155 {
 156     return g_ascii_isprint ((gchar) text[0]);
 157 }
 158 
 159 /* --------------------------------------------------------------------------------------------- */
 160 
 161 static gboolean
 162 str_ascii_iscombiningmark (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 163 {
 164     (void) text;
 165     return FALSE;
 166 }
 167 
 168 /* --------------------------------------------------------------------------------------------- */
 169 
 170 static int
 171 str_ascii_toupper (const char *text, char **out, size_t *remain)
     /* [previous][next][first][last][top][bottom][index][help]  */
 172 {
 173     if (*remain <= 1)
 174         return FALSE;
 175 
 176     (*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
 177     (*out)++;
 178     (*remain)--;
 179     return TRUE;
 180 }
 181 
 182 /* --------------------------------------------------------------------------------------------- */
 183 
 184 static gboolean
 185 str_ascii_tolower (const char *text, char **out, size_t *remain)
     /* [previous][next][first][last][top][bottom][index][help]  */
 186 {
 187     if (*remain <= 1)
 188         return FALSE;
 189 
 190     (*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
 191     (*out)++;
 192     (*remain)--;
 193     return TRUE;
 194 }
 195 
 196 /* --------------------------------------------------------------------------------------------- */
 197 
 198 static int
 199 str_ascii_length (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 200 {
 201     return strlen (text);
 202 }
 203 
 204 /* --------------------------------------------------------------------------------------------- */
 205 
 206 static int
 207 str_ascii_length2 (const char *text, int size)
     /* [previous][next][first][last][top][bottom][index][help]  */
 208 {
 209     size_t length;
 210 
 211     length = strlen (text);
 212 
 213     return (size >= 0) ? MIN (length, (size_t) size) : length;
 214 }
 215 
 216 /* --------------------------------------------------------------------------------------------- */
 217 
 218 static gchar *
 219 str_ascii_conv_gerror_message (GError *mcerror, const char *def_msg)
     /* [previous][next][first][last][top][bottom][index][help]  */
 220 {
 221     /* the same as str_utf8_conv_gerror_message() */
 222     if (mcerror != NULL)
 223         return g_strdup (mcerror->message);
 224 
 225     return g_strdup (def_msg != NULL ? def_msg : "");
 226 }
 227 
 228 /* --------------------------------------------------------------------------------------------- */
 229 
 230 static estr_t
 231 str_ascii_vfs_convert_to (GIConv coder, const char *string, int size, GString *buffer)
     /* [previous][next][first][last][top][bottom][index][help]  */
 232 {
 233     (void) coder;
 234     g_string_append_len (buffer, string, size);
 235     return ESTR_SUCCESS;
 236 }
 237 
 238 /* --------------------------------------------------------------------------------------------- */
 239 
 240 static const char *
 241 str_ascii_term_form (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 242 {
 243     static char result[BUF_MEDIUM];
 244     char *actual;
 245     size_t remain;
 246     size_t length;
 247     size_t pos = 0;
 248 
 249     actual = result;
 250     remain = sizeof (result);
 251     length = strlen (text);
 252 
 253     /* go throw all characters and check, if they are ascii and printable */
 254     for (; pos < length && remain > 1; pos++, actual++, remain--)
 255     {
 256         actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 257         actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 258     }
 259 
 260     actual[0] = '\0';
 261     return result;
 262 }
 263 
 264 /* --------------------------------------------------------------------------------------------- */
 265 
 266 static const char *
 267 str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
     /* [previous][next][first][last][top][bottom][index][help]  */
 268 {
 269     static char result[BUF_MEDIUM];
 270     char *actual;
 271     size_t remain;
 272     int ident = 0;
 273     size_t length;
 274     size_t pos = 0;
 275 
 276     length = strlen (text);
 277     actual = result;
 278     remain = sizeof (result);
 279 
 280     if ((int) length <= width)
 281     {
 282         switch (HIDE_FIT (just_mode))
 283         {
 284         case J_CENTER_LEFT:
 285         case J_CENTER:
 286             ident = (width - length) / 2;
 287             break;
 288         case J_RIGHT:
 289             ident = width - length;
 290             break;
 291         default:
 292             break;
 293         }
 294 
 295         /* add space before text */
 296         if ((int) remain <= ident)
 297             goto finally;
 298         memset (actual, ' ', ident);
 299         actual += ident;
 300         remain -= ident;
 301 
 302         /* copy all characters */
 303         for (; pos < (gsize) length && remain > 1; pos++, actual++, remain--)
 304         {
 305             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 306             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 307         }
 308 
 309         /* add space after text */
 310         if (width - length - ident > 0)
 311         {
 312             if (remain <= width - length - ident)
 313                 goto finally;
 314             memset (actual, ' ', width - length - ident);
 315             actual += width - length - ident;
 316         }
 317     }
 318     else if (IS_FIT (just_mode))
 319     {
 320         /* copy prefix of text, that is not wider than width / 2 */
 321         for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
 322         {
 323             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 324             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 325         }
 326 
 327         if (remain <= 1)
 328             goto finally;
 329         actual[0] = '~';
 330         actual++;
 331         remain--;
 332 
 333         pos += length - width + 1;
 334 
 335         /* copy suffix of text */
 336         for (; pos < length && remain > 1; pos++, actual++, remain--)
 337         {
 338             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 339             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 340         }
 341     }
 342     else
 343     {
 344         switch (HIDE_FIT (just_mode))
 345         {
 346         case J_CENTER:
 347             ident = (length - width) / 2;
 348             break;
 349         case J_RIGHT:
 350             ident = length - width;
 351             break;
 352         default:
 353             break;
 354         }
 355 
 356         /* copy substring text, substring start from ident and take width 
 357          * characters from text */
 358         pos += ident;
 359         for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--)
 360         {
 361             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 362             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 363         }
 364 
 365     }
 366 
 367   finally:
 368     if (actual >= result + sizeof (result))
 369         actual = result + sizeof (result) - 1;
 370     actual[0] = '\0';
 371     return result;
 372 }
 373 
 374 /* --------------------------------------------------------------------------------------------- */
 375 
 376 static const char *
 377 str_ascii_term_trim (const char *text, int width)
     /* [previous][next][first][last][top][bottom][index][help]  */
 378 {
 379     static char result[BUF_MEDIUM];
 380     size_t remain;
 381     char *actual;
 382     size_t length;
 383 
 384     length = strlen (text);
 385     actual = result;
 386     remain = sizeof (result);
 387 
 388     if (width > 0)
 389     {
 390         size_t pos;
 391 
 392         if (width >= (int) length)
 393         {
 394             /* copy all characters */
 395             for (pos = 0; pos < length && remain > 1; pos++, actual++, remain--)
 396             {
 397                 actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 398                 actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 399             }
 400         }
 401         else if (width <= 3)
 402         {
 403             memset (actual, '.', width);
 404             actual += width;
 405         }
 406         else
 407         {
 408             memset (actual, '.', 3);
 409             actual += 3;
 410             remain -= 3;
 411 
 412             /* copy suffix of text */
 413             for (pos = length - width + 3; pos < length && remain > 1; pos++, actual++, remain--)
 414             {
 415                 actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 416                 actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 417             }
 418         }
 419     }
 420 
 421     actual[0] = '\0';
 422     return result;
 423 }
 424 
 425 /* --------------------------------------------------------------------------------------------- */
 426 
 427 static int
 428 str_ascii_term_width2 (const char *text, size_t length)
     /* [previous][next][first][last][top][bottom][index][help]  */
 429 {
 430     size_t text_len;
 431 
 432     text_len = strlen (text);
 433 
 434     return (length != (size_t) (-1)) ? MIN (text_len, length) : text_len;
 435 }
 436 
 437 /* --------------------------------------------------------------------------------------------- */
 438 
 439 static int
 440 str_ascii_term_width1 (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 441 {
 442     return str_ascii_term_width2 (text, (size_t) (-1));
 443 }
 444 
 445 /* --------------------------------------------------------------------------------------------- */
 446 
 447 static int
 448 str_ascii_term_char_width (const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 449 {
 450     (void) text;
 451     return 1;
 452 }
 453 
 454 /* --------------------------------------------------------------------------------------------- */
 455 
 456 static const char *
 457 str_ascii_term_substring (const char *text, int start, int width)
     /* [previous][next][first][last][top][bottom][index][help]  */
 458 {
 459     static char result[BUF_MEDIUM];
 460     size_t remain;
 461     char *actual;
 462     size_t length;
 463 
 464     actual = result;
 465     remain = sizeof (result);
 466     length = strlen (text);
 467 
 468     if (start < (int) length)
 469     {
 470         size_t pos;
 471 
 472         /* copy at most width characters from text from start */
 473         for (pos = start; pos < length && width > 0 && remain > 1;
 474              pos++, width--, actual++, remain--)
 475         {
 476             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 477             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 478         }
 479     }
 480 
 481     /* if text is shorter then width, add space to the end */
 482     for (; width > 0 && remain > 1; actual++, remain--, width--)
 483         actual[0] = ' ';
 484 
 485     actual[0] = '\0';
 486     return result;
 487 }
 488 
 489 /* --------------------------------------------------------------------------------------------- */
 490 
 491 static const char *
 492 str_ascii_trunc (const char *text, int width)
     /* [previous][next][first][last][top][bottom][index][help]  */
 493 {
 494     static char result[MC_MAXPATHLEN];
 495     int remain;
 496     char *actual;
 497     size_t pos = 0;
 498     size_t length;
 499 
 500     actual = result;
 501     remain = sizeof (result);
 502     length = strlen (text);
 503 
 504     if ((int) length > width)
 505     {
 506         /* copy prefix of text */
 507         for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
 508         {
 509             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 510             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 511         }
 512 
 513         if (remain <= 1)
 514             goto finally;
 515         actual[0] = '~';
 516         actual++;
 517         remain--;
 518 
 519         pos += length - width + 1;
 520 
 521         /* copy suffix of text */
 522         for (; pos < length && remain > 1; pos++, actual++, remain--)
 523         {
 524             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 525             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 526         }
 527     }
 528     else
 529     {
 530         /* copy all characters */
 531         for (; pos < length && remain > 1; pos++, actual++, remain--)
 532         {
 533             actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
 534             actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
 535         }
 536     }
 537 
 538   finally:
 539     actual[0] = '\0';
 540     return result;
 541 }
 542 
 543 /* --------------------------------------------------------------------------------------------- */
 544 
 545 static int
 546 str_ascii_offset_to_pos (const char *text, size_t length)
     /* [previous][next][first][last][top][bottom][index][help]  */
 547 {
 548     (void) text;
 549     return (int) length;
 550 }
 551 
 552 /* --------------------------------------------------------------------------------------------- */
 553 
 554 static int
 555 str_ascii_column_to_pos (const char *text, size_t pos)
     /* [previous][next][first][last][top][bottom][index][help]  */
 556 {
 557     (void) text;
 558     return (int) pos;
 559 }
 560 
 561 /* --------------------------------------------------------------------------------------------- */
 562 
 563 static char *
 564 str_ascii_create_search_needle (const char *needle, gboolean case_sen)
     /* [previous][next][first][last][top][bottom][index][help]  */
 565 {
 566     (void) case_sen;
 567     return (char *) needle;
 568 }
 569 
 570 /* --------------------------------------------------------------------------------------------- */
 571 
 572 static void
 573 str_ascii_release_search_needle (char *needle, gboolean case_sen)
     /* [previous][next][first][last][top][bottom][index][help]  */
 574 {
 575     (void) case_sen;
 576     (void) needle;
 577 
 578 }
 579 
 580 /* --------------------------------------------------------------------------------------------- */
 581 
 582 static const char *
 583 str_ascii_search_first (const char *text, const char *search, gboolean case_sen)
     /* [previous][next][first][last][top][bottom][index][help]  */
 584 {
 585     char *fold_text;
 586     char *fold_search;
 587     const char *match;
 588 
 589     fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1);
 590     fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1);
 591 
 592     match = g_strstr_len (fold_text, -1, fold_search);
 593     if (match != NULL)
 594     {
 595         size_t offset;
 596 
 597         offset = match - fold_text;
 598         match = text + offset;
 599     }
 600 
 601     if (!case_sen)
 602     {
 603         g_free (fold_text);
 604         g_free (fold_search);
 605     }
 606 
 607     return match;
 608 }
 609 
 610 /* --------------------------------------------------------------------------------------------- */
 611 
 612 static const char *
 613 str_ascii_search_last (const char *text, const char *search, gboolean case_sen)
     /* [previous][next][first][last][top][bottom][index][help]  */
 614 {
 615     char *fold_text;
 616     char *fold_search;
 617     const char *match;
 618 
 619     fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1);
 620     fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1);
 621 
 622     match = g_strrstr_len (fold_text, -1, fold_search);
 623     if (match != NULL)
 624     {
 625         size_t offset;
 626 
 627         offset = match - fold_text;
 628         match = text + offset;
 629     }
 630 
 631     if (!case_sen)
 632     {
 633         g_free (fold_text);
 634         g_free (fold_search);
 635     }
 636 
 637     return match;
 638 }
 639 
 640 /* --------------------------------------------------------------------------------------------- */
 641 
 642 static int
 643 str_ascii_compare (const char *t1, const char *t2)
     /* [previous][next][first][last][top][bottom][index][help]  */
 644 {
 645     return strcmp (t1, t2);
 646 }
 647 
 648 /* --------------------------------------------------------------------------------------------- */
 649 
 650 static int
 651 str_ascii_ncompare (const char *t1, const char *t2)
     /* [previous][next][first][last][top][bottom][index][help]  */
 652 {
 653     size_t l1, l2;
 654 
 655     l1 = strlen (t1);
 656     l2 = strlen (t2);
 657 
 658     return strncmp (t1, t2, MIN (l1, l2));
 659 }
 660 
 661 /* --------------------------------------------------------------------------------------------- */
 662 
 663 static int
 664 str_ascii_casecmp (const char *t1, const char *t2)
     /* [previous][next][first][last][top][bottom][index][help]  */
 665 {
 666     return g_ascii_strcasecmp (t1, t2);
 667 }
 668 
 669 /* --------------------------------------------------------------------------------------------- */
 670 
 671 static int
 672 str_ascii_ncasecmp (const char *t1, const char *t2)
     /* [previous][next][first][last][top][bottom][index][help]  */
 673 {
 674     size_t l1, l2;
 675 
 676     l1 = strlen (t1);
 677     l2 = strlen (t2);
 678 
 679     return g_ascii_strncasecmp (t1, t2, MIN (l1, l2));
 680 }
 681 
 682 /* --------------------------------------------------------------------------------------------- */
 683 
 684 static void
 685 str_ascii_fix_string (char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 686 {
 687     for (; text[0] != '\0'; text++)
 688         text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
 689 }
 690 
 691 /* --------------------------------------------------------------------------------------------- */
 692 
 693 static char *
 694 str_ascii_create_key (const char *text, gboolean case_sen)
     /* [previous][next][first][last][top][bottom][index][help]  */
 695 {
 696     (void) case_sen;
 697     return (char *) text;
 698 }
 699 
 700 /* --------------------------------------------------------------------------------------------- */
 701 
 702 static int
 703 str_ascii_key_collate (const char *t1, const char *t2, gboolean case_sen)
     /* [previous][next][first][last][top][bottom][index][help]  */
 704 {
 705     return case_sen ? strcmp (t1, t2) : g_ascii_strcasecmp (t1, t2);
 706 }
 707 
 708 /* --------------------------------------------------------------------------------------------- */
 709 
 710 static void
 711 str_ascii_release_key (char *key, gboolean case_sen)
     /* [previous][next][first][last][top][bottom][index][help]  */
 712 {
 713     (void) key;
 714     (void) case_sen;
 715 }
 716 
 717 /* --------------------------------------------------------------------------------------------- */
 718 
 719 static int
 720 str_ascii_prefix (const char *text, const char *prefix)
     /* [previous][next][first][last][top][bottom][index][help]  */
 721 {
 722     int result;
 723 
 724     for (result = 0; text[result] != '\0' && prefix[result] != '\0'
 725          && text[result] == prefix[result]; result++);
 726 
 727     return result;
 728 }
 729 
 730 /* --------------------------------------------------------------------------------------------- */
 731 
 732 static int
 733 str_ascii_caseprefix (const char *text, const char *prefix)
     /* [previous][next][first][last][top][bottom][index][help]  */
 734 {
 735     int result;
 736 
 737     for (result = 0; text[result] != '\0' && prefix[result] != '\0'
 738          && g_ascii_toupper (text[result]) == g_ascii_toupper (prefix[result]); result++);
 739 
 740     return result;
 741 }
 742 
 743 /* --------------------------------------------------------------------------------------------- */
 744 /*** public functions ****************************************************************************/
 745 /* --------------------------------------------------------------------------------------------- */
 746 
 747 struct str_class
 748 str_ascii_init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 749 {
 750     struct str_class result;
 751 
 752     result.conv_gerror_message = str_ascii_conv_gerror_message;
 753     result.vfs_convert_to = str_ascii_vfs_convert_to;
 754     result.insert_replace_char = str_ascii_insert_replace_char;
 755     result.is_valid_string = str_ascii_is_valid_string;
 756     result.is_valid_char = str_ascii_is_valid_char;
 757     result.cnext_char = str_ascii_cnext_char;
 758     result.cprev_char = str_ascii_cprev_char;
 759     result.cnext_char_safe = str_ascii_cnext_char;
 760     result.cprev_char_safe = str_ascii_cprev_char;
 761     result.cnext_noncomb_char = str_ascii_cnext_noncomb_char;
 762     result.cprev_noncomb_char = str_ascii_cprev_noncomb_char;
 763     result.char_isspace = str_ascii_isspace;
 764     result.char_ispunct = str_ascii_ispunct;
 765     result.char_isalnum = str_ascii_isalnum;
 766     result.char_isdigit = str_ascii_isdigit;
 767     result.char_isprint = str_ascii_isprint;
 768     result.char_iscombiningmark = str_ascii_iscombiningmark;
 769     result.char_toupper = str_ascii_toupper;
 770     result.char_tolower = str_ascii_tolower;
 771     result.length = str_ascii_length;
 772     result.length2 = str_ascii_length2;
 773     result.length_noncomb = str_ascii_length;
 774     result.fix_string = str_ascii_fix_string;
 775     result.term_form = str_ascii_term_form;
 776     result.fit_to_term = str_ascii_fit_to_term;
 777     result.term_trim = str_ascii_term_trim;
 778     result.term_width2 = str_ascii_term_width2;
 779     result.term_width1 = str_ascii_term_width1;
 780     result.term_char_width = str_ascii_term_char_width;
 781     result.term_substring = str_ascii_term_substring;
 782     result.trunc = str_ascii_trunc;
 783     result.offset_to_pos = str_ascii_offset_to_pos;
 784     result.column_to_pos = str_ascii_column_to_pos;
 785     result.create_search_needle = str_ascii_create_search_needle;
 786     result.release_search_needle = str_ascii_release_search_needle;
 787     result.search_first = str_ascii_search_first;
 788     result.search_last = str_ascii_search_last;
 789     result.compare = str_ascii_compare;
 790     result.ncompare = str_ascii_ncompare;
 791     result.casecmp = str_ascii_casecmp;
 792     result.ncasecmp = str_ascii_ncasecmp;
 793     result.prefix = str_ascii_prefix;
 794     result.caseprefix = str_ascii_caseprefix;
 795     result.create_key = str_ascii_create_key;
 796     result.create_key_for_filename = str_ascii_create_key;
 797     result.key_collate = str_ascii_key_collate;
 798     result.release_key = str_ascii_release_key;
 799 
 800     return result;
 801 }
 802 
 803 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */