Bump S-nail v14.9.25 ("Lubimy Gorod"), 2024-06-27
[s-mailx.git] / src / su / cs-rfind.c
blob96c283bbec84a259da156c503ccf83ff9e2e0c33
1 /*@ Implementation of cs.h: reverse finding related things.
2 *@ TODO Optimize (even asm hooks?)
4 * Copyright (c) 2017 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
5 * SPDX-License-Identifier: ISC
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.
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.
19 #undef su_FILE
20 #define su_FILE su_cs_rfind
21 #define su_SOURCE
22 #define su_SOURCE_CS_RFIND
24 #include "su/code.h"
26 #include "su/cs.h"
27 #include "su/code-in.h"
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);
37 rv = FAL0;
39 if(LIKELY(*xp != '\0')){
40 uz cl, xl;
42 cl = su_cs_len(cp);
43 xl = su_cs_len(xp);
45 if(cl < xl)
46 goto jleave;
48 for(cp += cl - xl;; ++cp, ++xp){
49 char c, xc;
51 if((c = su_cs_to_lower(*cp)) != (xc = su_cs_to_lower(*xp)))
52 break;
54 if(xc == '\0'){
55 rv = TRU1;
56 break;
61 jleave:
62 NYD_OU;
63 return rv;
65 #endif /* 0 */
67 char *
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);
73 for(match = NIL, tail = cp;; ++tail){
74 char c;
76 if((c = *tail) == x)
77 match = tail;
78 if(c == '\0')
79 break;
82 NYD_OU;
83 return UNCONST(char*,match);
86 #include "su/code-ou.h"
87 /* s-it-mode */