1 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
2 <link rel="stylesheet" href="style.css" type="text/css"/>
3 <script src="code.js" type="text/javascript"></script>
5 <h1>glibc strverscmp</h1>
8 <span class="comment">/* Compare S1 and S2 as strings holding indices/version numbers,
9 returning less than, equal to or greater than zero if S1 is less than,
10 equal to or greater than S2 (for more info, see the texinfo doc).
14 __strverscmp (const char *s1, const char *s2)
16 const unsigned char *p1 = (const unsigned char *) s1;
17 const unsigned char *p2 = (const unsigned char *) s2;
19 /* Symbol(s) 0 [1-9] others
20 Transition (10) 0 (01) d (00) x */
21 static const uint8_t next_state[] =
24 /* S_N */ S_N, S_I, S_Z,
25 /* S_I */ S_N, S_I, S_I,
26 /* S_F */ S_N, S_F, S_F,
27 /* S_Z */ S_N, S_F, S_Z
30 static const int8_t result_type[] =
32 /* state x/x x/d x/0 d/x d/d d/0 0/x 0/d 0/0 */
34 /* S_N */ CMP, CMP, CMP, CMP, LEN, CMP, CMP, CMP, CMP,
35 /* S_I */ CMP, -1, -1, +1, LEN, LEN, +1, LEN, LEN,
36 /* S_F */ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
37 /* S_Z */ CMP, +1, +1, -1, CMP, CMP, -1, CMP, CMP
43 unsigned char c1 = *p1++;
44 unsigned char c2 = *p2++;
45 /* Hint: '0' is a digit too. */
46 int state = S_N + ((c1 == '0') + (__my_isdigit (c1) != 0));
49 while ((diff = c1 - c2) == 0)
54 state = next_state[state];
57 state += (c1 == '0') + (__my_isdigit (c1) != 0);
60 state = result_type[state * 3 + (((c2 == '0') + (__my_isdigit (c2) != 0)))];
68 while (__my_isdigit (*p1++))
69 if (!__my_isdigit (*p2++))
72 return __my_isdigit (*p2) ? -1 : diff;