comparison th_string.c @ 735:31bc1ed07cf5

Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Dec 2022 12:14:39 +0200
parents 29e44a58bc73
children 4181d43f91f9
comparison
equal deleted inserted replaced
734:2ae1045f6c18 735:31bc1ed07cf5
592 592
593 593
594 int th_split_string_elems(const th_char_t *str, th_strelems_t *ctx, const th_char_t *sep) 594 int th_split_string_elems(const th_char_t *str, th_strelems_t *ctx, const th_char_t *sep)
595 { 595 {
596 size_t start = 0, end; 596 size_t start = 0, end;
597 BOOL match = FALSE; 597 bool match = false;
598 598
599 if (str == NULL || ctx == NULL || sep == NULL) 599 if (str == NULL || ctx == NULL || sep == NULL)
600 return THERR_NULLPTR; 600 return THERR_NULLPTR;
601 601
602 ctx->elems = NULL; 602 ctx->elems = NULL;
603 ctx->nelems = 0; 603 ctx->nelems = 0;
604 604
605 do 605 do
606 { 606 {
607 // Split foremost str element out 607 // Split foremost str element out
608 match = FALSE; 608 match = false;
609 for (end = start; str[end] != 0; end++) 609 for (end = start; str[end] != 0; end++)
610 { 610 {
611 if (th_strchr(sep, str[end])) 611 if (th_strchr(sep, str[end]))
612 { 612 {
613 match = TRUE; 613 match = true;
614 break; 614 break;
615 } 615 }
616 } 616 }
617 617
618 // If the element is there, create it 618 // If the element is there, create it
784 #define TH_STRGLOB_FUNC th_strcasematch 784 #define TH_STRGLOB_FUNC th_strcasematch
785 #define TH_STRGLOB_COLLATE(px) th_tolower(px) 785 #define TH_STRGLOB_COLLATE(px) th_tolower(px)
786 #include "th_strglob.c" 786 #include "th_strglob.c"
787 787
788 788
789 BOOL th_get_hex_triplet(const th_char_t *str, unsigned int *value) 789 bool th_get_hex_triplet(const th_char_t *str, unsigned int *value)
790 { 790 {
791 const th_char_t *p = str; 791 const th_char_t *p = str;
792 int len; 792 int len;
793 *value = 0; 793 *value = 0;
794 794
810 { 810 {
811 (*value) <<= 4; 811 (*value) <<= 4;
812 (*value) |= (*p - 'a') + 10; 812 (*value) |= (*p - 'a') + 10;
813 } 813 }
814 else 814 else
815 return FALSE; 815 return false;
816 } 816 }
817 817
818 return (len >= 3 * 2 && len <= 4 * 2); 818 return (len >= 3 * 2 && len <= 4 * 2);
819 } 819 }
820 820
821 821
822 BOOL th_get_boolean(const th_char_t *str, BOOL *value) 822 bool th_get_boolean(const th_char_t *str, bool *value)
823 { 823 {
824 if (!th_strcasecmp(str, "yes") || 824 if (!th_strcasecmp(str, "yes") ||
825 !th_strcasecmp(str, "on") || 825 !th_strcasecmp(str, "on") ||
826 !th_strcasecmp(str, "true") || 826 !th_strcasecmp(str, "true") ||
827 !th_strcasecmp(str, "1")) 827 !th_strcasecmp(str, "1"))
828 { 828 {
829 *value = TRUE; 829 *value = true;
830 return TRUE; 830 return true;
831 } 831 }
832 else 832 else
833 if (!th_strcasecmp(str, "no") || 833 if (!th_strcasecmp(str, "no") ||
834 !th_strcasecmp(str, "off") || 834 !th_strcasecmp(str, "off") ||
835 !th_strcasecmp(str, "false") || 835 !th_strcasecmp(str, "false") ||
836 !th_strcasecmp(str, "0")) 836 !th_strcasecmp(str, "0"))
837 { 837 {
838 *value = FALSE; 838 *value = false;
839 return TRUE; 839 return true;
840 } 840 }
841 else 841 else
842 return FALSE; 842 return false;
843 } 843 }
844 844
845 845
846 BOOL th_get_int(const th_char_t *str, unsigned int *value, BOOL *neg) 846 bool th_get_int(const th_char_t *str, unsigned int *value, bool *neg)
847 { 847 {
848 int ch; 848 int ch;
849 BOOL hex = FALSE; 849 bool hex = false;
850 850
851 // Is the value negative? 851 // Is the value negative?
852 if (*str == '-') 852 if (*str == '-')
853 { 853 {
854 if (neg == NULL) 854 if (neg == NULL)
855 return FALSE; 855 return false;
856 856
857 *neg = TRUE; 857 *neg = true;
858 str++; 858 str++;
859 } 859 }
860 else 860 else
861 if (neg != NULL) 861 if (neg != NULL)
862 *neg = FALSE; 862 *neg = false;
863 863
864 // Is it hexadecimal? 864 // Is it hexadecimal?
865 if (*str == '$') 865 if (*str == '$')
866 { 866 {
867 hex = TRUE; 867 hex = true;
868 str++; 868 str++;
869 } 869 }
870 else 870 else
871 if (str[0] == '0' && str[1] == 'x') 871 if (str[0] == '0' && str[1] == 'x')
872 { 872 {
873 hex = TRUE; 873 hex = true;
874 str += 2; 874 str += 2;
875 } 875 }
876 876
877 // Parse the value 877 // Parse the value
878 *value = 0; 878 *value = 0;
896 { 896 {
897 *value <<= 4; 897 *value <<= 4;
898 *value |= ch - 'a' + 10; 898 *value |= ch - 'a' + 10;
899 } 899 }
900 else 900 else
901 return FALSE; 901 return false;
902 } 902 }
903 } 903 }
904 else 904 else
905 { 905 {
906 while ((ch = *str++)) 906 while ((ch = *str++))
909 { 909 {
910 *value *= 10; 910 *value *= 10;
911 *value += ch - '0'; 911 *value += ch - '0';
912 } 912 }
913 else 913 else
914 return FALSE; 914 return false;
915 } 915 }
916 } 916 }
917 return TRUE; 917 return true;
918 } 918 }