File: String.c

package info (click to toggle)
cmake 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 158,704 kB
  • sloc: ansic: 406,077; cpp: 309,512; sh: 4,233; python: 3,696; yacc: 3,109; lex: 1,279; f90: 538; asm: 471; lisp: 375; java: 310; cs: 270; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 110; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22; sed: 2
file content (146 lines) | stat: -rw-r--r-- 4,069 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
#ifdef KWSYS_STRING_C
/*
All code in this source file is conditionally compiled to work-around
template definition auto-search on VMS.  Other source files in this
directory that use the stl string cause the compiler to load this
source to try to get the definition of the string template.  This
condition blocks the compiler from seeing the symbols defined here.
*/
#  include "kwsysPrivate.h"
#  include KWSYS_HEADER(String.h)

/* Work-around CMake dependency scanning limitation.  This must
   duplicate the above list of headers.  */
#  if 0
#    include "String.h.in"
#  endif

#  include <ctype.h>

int kwsysString_isalnum(char c)
{
  return (kwsysString_isalpha(c) | /* bitwise-or to avoid branching.  */
          kwsysString_isdigit(c));
}

int kwsysString_isalpha(char c)
{
  return (kwsysString_islower(c) | /* bitwise-or to avoid branching.  */
          kwsysString_isupper(c));
}

int kwsysString_isascii(char c)
{
  unsigned char const uc = (unsigned char)c;
  return (uc & 0x80) ^ 0x80;
}

int kwsysString_isblank(char c)
{
  unsigned char const uc = (unsigned char)c;
  return uc < 0x80 && isblank(uc);
}

int kwsysString_iscntrl(char c)
{
  unsigned char const uc = (unsigned char)c;
  return uc < 0x80 && iscntrl(uc);
}

int kwsysString_isdigit(char c)
{
  unsigned char const uc = (unsigned char)c;
  /* Push '0-9' to 246-255 so integer division by 246 is 1 only for them.  */
  return ((uc + 246 - '0') & 0xFF) / 246;
}

int kwsysString_isgraph(char c)
{
  unsigned char const uc = (unsigned char)c;
  return uc < 0x80 && isgraph(uc);
}

int kwsysString_islower(char c)
{
  unsigned char const uc = (unsigned char)c;
  /* Push 'a-z' to 230-255 so integer division by 230 is 1 only for them.  */
  return ((uc + 230 - 'a') & 0xFF) / 230;
}

int kwsysString_isprint(char c)
{
  unsigned char const uc = (unsigned char)c;
  /* Push 32-126 to 161-255 so integer division by 161 is 1 only for them.  */
  return ((uc + 161 - ' ') & 0xFF) / 161;
}

int kwsysString_ispunct(char c)
{
  unsigned char const uc = (unsigned char)c;
  return uc < 0x80 && ispunct(uc);
}

int kwsysString_isspace(char c)
{
  unsigned char const uc = (unsigned char)c;
  return uc < 0x80 && isspace(uc);
}

int kwsysString_isupper(char c)
{
  unsigned char const uc = (unsigned char)c;
  /* Push 'A-Z' to 230-255 so integer division by 230 is 1 only for them.  */
  return ((uc + 230 - 'A') & 0xFF) / 230;
}

int kwsysString_isxdigit(char c)
{
  unsigned char const uc = (unsigned char)c;
  return (
    /* Push '0-9' to 246-255 so integer division by 246 is 1 only for them.  */
    (((uc + 246 - '0') & 0xFF) / 246) | /* bitwise-or to avoid branching.    */
    /* Push 'A-F' to 250-255 so integer division by 250 is 1 only for them.  */
    (((uc + 250 - 'A') & 0xFF) / 250) | /* bitwise-or to avoid branching.    */
    /* Push 'a-f' to 250-255 so integer division by 250 is 1 only for them.  */
    (((uc + 250 - 'a') & 0xFF) / 250));
}

unsigned char kwsysString_tolower(char c)
{
  unsigned char const uc = (unsigned char)c;
  /* Push 'A-Z' to 230-255 so integer division by 230 is 1 only for them.  */
  return (unsigned char)(uc ^ ((((uc + 230 - 'A') & 0xFF) / 230) << 5));
}

unsigned char kwsysString_toupper(char c)
{
  unsigned char const uc = (unsigned char)c;
  /* Push 'a-z' to 230-255 so integer division by 230 is 1 only for them.  */
  return (unsigned char)(uc ^ ((((uc + 230 - 'a') & 0xFF) / 230) << 5));
}

int kwsysString_strcasecmp(char const* lhs, char const* rhs)
{
  int result;
  while ((result = kwsysString_tolower(*lhs) - kwsysString_tolower(*rhs++)) ==
           0 &&
         *lhs++) {
  }
  return result;
}

int kwsysString_strncasecmp(char const* lhs, char const* rhs, size_t n)
{
  int result = 0;
  while (n &&
         (result = kwsysString_tolower(*lhs) - kwsysString_tolower(*rhs++)) ==
           0 &&
         *lhs++) {
    --n;
  }
  return result;
}

#endif /* KWSYS_STRING_C */