glitchedhttps
glitchedhttps_strutil.h
Go to the documentation of this file.
1/*
2 Copyright 2020 Raphael Beck
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
22#ifndef GLITCHEDHTTPS_STRUTIL_H
23#define GLITCHEDHTTPS_STRUTIL_H
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#include <ctype.h>
30#include <string.h>
31
39GLITCHEDHTTPS_API int glitchedhttps_strncmpic(const char* str1, const char* str2, size_t n)
40{
41 size_t cmp = 0;
42 int ret = INT_MIN;
43
44 if (str1 == NULL || str2 == NULL)
45 {
46 return ret;
47 }
48
49 while ((*str1 || *str2) && cmp < n)
50 {
51 if ((ret = tolower((int)(*str1)) - tolower((int)(*str2))) != 0)
52 {
53 break;
54 }
55 ++cmp;
56 ++str1;
57 ++str2;
58 }
59
60 return ret;
61}
62
68static inline int glitchedhttps_is_http(const char* url)
69{
70 return strlen(url) >= 7 && strncmp(url, "http://", 7) == 0;
71}
72
78static inline int glitchedhttps_is_https(const char* url)
79{
80 return strlen(url) >= 8 && strncmp(url, "https://", 8) == 0;
81}
82
88static inline size_t glitchedhttps_count_digits(const size_t number)
89{
90 size_t n = number, digits = 0;
91 while (n != 0)
92 {
93 n /= 10;
94 ++digits;
95 }
96 return digits;
97}
98
99#ifdef __cplusplus
100} // extern "C"
101#endif
102
103#endif // GLITCHEDHTTPS_STRUTIL_H
static int glitchedhttps_is_https(const char *url)
Definition: glitchedhttps_strutil.h:78
static size_t glitchedhttps_count_digits(const size_t number)
Definition: glitchedhttps_strutil.h:88
GLITCHEDHTTPS_API int glitchedhttps_strncmpic(const char *str1, const char *str2, size_t n)
Definition: glitchedhttps_strutil.h:39
static int glitchedhttps_is_http(const char *url)
Definition: glitchedhttps_strutil.h:68