1 /*@ Implementation of cs.h: reverse finding related things.
2 *@ TODO Optimize (even asm hooks?)
3 *
4 * Copyright (c) 2017 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
5 * SPDX-License-Identifier: ISC
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19 #undef su_FILE
20 #define su_FILE su_cs_rfind
21 #define su_SOURCE
22 #define su_SOURCE_CS_RFIND
23
24 #include "su/code.h"
25
26 #include "su/cs.h"
27 #include "su/code-in.h"
28
29 #if 0
30 boole
31 su_cs_ends_with_case(char const *cp, char const *xp){
32 boole rv;
33 NYD_IN;
34 ASSERT_NYD_EXEC(cp != NIL, rv = FAL0);
35 ASSERT_NYD_EXEC(xp != NIL, rv = FAL0);
36
37 rv = FAL0;
38
39 if(LIKELY(*xp != '\0')){
40 uz cl, xl;
41
42 cl = su_cs_len(cp);
43 xl = su_cs_len(xp);
44
45 if(cl < xl)
46 goto jleave;
47
48 for(cp += cl - xl;; ++cp, ++xp){
49 char c, xc;
50
51 if((c = su_cs_to_lower(*cp)) != (xc = su_cs_to_lower(*xp)))
52 break;
53
54 if(xc == '\0'){
55 rv = TRU1;
56 break;
57 }
58 }
59 }
60
61 jleave:
62 NYD_OU;
63 return rv;
64 }
65 #endif /* 0 */
66
67 char *
su_cs_rfind_c(char const * cp,char x)68 su_cs_rfind_c(char const *cp, char x){
69 char const *match, *tail;
70 NYD_IN;
71 ASSERT_NYD_EXEC(cp != NIL, match = NIL);
72
73 for(match = NIL, tail = cp;; ++tail){
74 char c;
75
76 if((c = *tail) == x)
77 match = tail;
78 if(c == '\0')
79 break;
80 }
81
82 NYD_OU;
83 return UNCONST(char*,match);
84 }
85
86 #include "su/code-ou.h"
87 /* s-it-mode */
88