ucx/string.c

Sun, 17 Jun 2018 09:50:05 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 17 Jun 2018 09:50:05 +0200
changeset 423
84e6c407b431
parent 335
c1bc13faadaa
child 505
481802342fdf
permissions
-rw-r--r--

adds support for tag colors

1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
3 *
335
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
4 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
5 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
6 * Redistribution and use in source and binary forms, with or without
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
7 * modification, are permitted provided that the following conditions are met:
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
8 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
14 * documentation and/or other materials provided with the distribution.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
15 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
335
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
29 #include "ucx/string.h"
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
30
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
31 #include "ucx/allocator.h"
c1bc13faadaa updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 314
diff changeset
32
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <stdlib.h>
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <string.h>
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include <stdarg.h>
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
36 #include <stdint.h>
81
8e186185422c UCX string module update
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
37 #include <ctype.h>
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
39 sstr_t sstr(char *cstring) {
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 sstr_t string;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
41 string.ptr = cstring;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
42 string.length = strlen(cstring);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 return string;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
46 sstr_t sstrn(char *cstring, size_t length) {
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 sstr_t string;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
48 string.ptr = cstring;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
49 string.length = length;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 return string;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 size_t sstrnlen(size_t n, sstr_t s, ...) {
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 va_list ap;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 size_t size = s.length;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 va_start(ap, s);
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
58 for (size_t i = 1 ; i < n ; i++) {
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 sstr_t str = va_arg(ap, sstr_t);
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 size += str.length;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 va_end(ap);
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 return size;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
67 static sstr_t sstrvcat_a(
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
68 UcxAllocator *a,
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
69 size_t count,
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
70 sstr_t s1,
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
71 sstr_t s2,
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
72 va_list ap) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
73 sstr_t str;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
74 str.ptr = NULL;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
75 str.length = 0;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
76 if(count < 2) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
77 return str;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
78 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
80 sstr_t *strings = (sstr_t*) calloc(count, sizeof(sstr_t));
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
81 if(!strings) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
82 return str;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
83 }
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
84
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
85 // get all args and overall length
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
86 strings[0] = s1;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
87 strings[1] = s2;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
88 size_t strlen = s1.length + s2.length;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
89 for (size_t i=2;i<count;i++) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
90 sstr_t s = va_arg (ap, sstr_t);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
91 strings[i] = s;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
92 strlen += s.length;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
93 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
95 // create new string
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
96 str.ptr = (char*) almalloc(a, strlen + 1);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
97 str.length = strlen;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
98 if(!str.ptr) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
99 free(strings);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
100 str.length = 0;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
101 return str;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
102 }
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
103
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
104 // concatenate strings
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
105 size_t pos = 0;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
106 for (size_t i=0;i<count;i++) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
107 sstr_t s = strings[i];
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
108 memcpy(str.ptr + pos, s.ptr, s.length);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
109 pos += s.length;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
111
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
112 str.ptr[str.length] = '\0';
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
113
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
114 free(strings);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
115
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
116 return str;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
117 }
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
118
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
119 sstr_t sstrcat(size_t count, sstr_t s1, sstr_t s2, ...) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
120 va_list ap;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
121 va_start(ap, s2);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
122 sstr_t s = sstrvcat_a(ucx_default_allocator(), count, s1, s2, ap);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 va_end(ap);
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
124 return s;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
125 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
127 sstr_t sstrcat_a(UcxAllocator *a, size_t count, sstr_t s1, sstr_t s2, ...) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
128 va_list ap;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
129 va_start(ap, s2);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
130 sstr_t s = sstrvcat_a(a, count, s1, s2, ap);
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
131 va_end(ap);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 return s;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 sstr_t sstrsubs(sstr_t s, size_t start) {
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 return sstrsubsl (s, start, s.length-start);
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 sstr_t sstrsubsl(sstr_t s, size_t start, size_t length) {
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 sstr_t new_sstr;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
141 if (start >= s.length) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
142 new_sstr.ptr = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 39
diff changeset
143 new_sstr.length = 0;
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
144 } else {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
145 if (length > s.length-start) {
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
146 length = s.length-start;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
147 }
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
148 new_sstr.ptr = &s.ptr[start];
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
149 new_sstr.length = length;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 return new_sstr;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
154 sstr_t sstrchr(sstr_t s, int c) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
155 for(size_t i=0;i<s.length;i++) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
156 if(s.ptr[i] == c) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
157 return sstrsubs(s, i);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
158 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
159 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
160 sstr_t n;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
161 n.ptr = NULL;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
162 n.length = 0;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
163 return n;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
164 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
165
39
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
166 sstr_t sstrrchr(sstr_t s, int c) {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
167 if (s.length > 0) {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
168 for(size_t i=s.length;i>0;i--) {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
169 if(s.ptr[i-1] == c) {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
170 return sstrsubs(s, i-1);
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
171 }
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
172 }
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
173 }
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
174 sstr_t n;
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
175 n.ptr = NULL;
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
176 n.length = 0;
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
177 return n;
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
178 }
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
179
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
180 #define ptable_r(dest, useheap, ptable, index) (dest = useheap ? \
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
181 ((size_t*)ptable)[index] : (size_t) ((uint8_t*)ptable)[index])
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
182
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
183 #define ptable_w(useheap, ptable, index, src) do {\
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
184 if (!useheap) ((uint8_t*)ptable)[index] = (uint8_t) src;\
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
185 else ((size_t*)ptable)[index] = src;\
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
186 } while (0);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
187
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
188 sstr_t sstrstr(sstr_t string, sstr_t match) {
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
189 if (match.length == 0) {
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
190 return string;
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
191 }
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
192
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
193 /* prepare default return value in case of no match */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
194 sstr_t result = sstrn(NULL, 0);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
195
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
196 /*
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
197 * IMPORTANT:
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
198 * our prefix table contains the prefix length PLUS ONE
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
199 * this is our decision, because we want to use the full range of size_t
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
200 * the original algorithm needs a (-1) at one single place
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
201 * and we want to avoid that
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
202 */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
203
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
204 /* static prefix table */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
205 static uint8_t s_prefix_table[256];
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
206
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
207 /* check pattern length and use appropriate prefix table */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
208 /* if the pattern exceeds static prefix table, allocate on the heap */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
209 register int useheap = match.length > 255;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
210 register void* ptable = useheap ?
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
211 calloc(match.length+1, sizeof(size_t)): s_prefix_table;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
212
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
213 /* keep counter in registers */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
214 register size_t i, j;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
215
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
216 /* fill prefix table */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
217 i = 0; j = 0;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
218 ptable_w(useheap, ptable, i, j);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
219 while (i < match.length) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
220 while (j >= 1 && match.ptr[j-1] != match.ptr[i]) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
221 ptable_r(j, useheap, ptable, j-1);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
222 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
223 i++; j++;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
224 ptable_w(useheap, ptable, i, j);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
225 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
226
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
227 /* search */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
228 i = 0; j = 1;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
229 while (i < string.length) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
230 while (j >= 1 && string.ptr[i] != match.ptr[j-1]) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
231 ptable_r(j, useheap, ptable, j-1);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
232 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
233 i++; j++;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
234 if (j-1 == match.length) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
235 size_t start = i - match.length;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
236 result.ptr = string.ptr + start;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
237 result.length = string.length - start;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
238 break;
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
239 }
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
240 }
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
241
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
242 /* if prefix table was allocated on the heap, free it */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
243 if (ptable != s_prefix_table) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
244 free(ptable);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
245 }
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
246
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
247 return result;
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
248 }
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 174
diff changeset
249
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
250 #undef ptable_r
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
251 #undef ptable_w
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
252
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
253 sstr_t* sstrsplit(sstr_t s, sstr_t d, ssize_t *n) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
254 return sstrsplit_a(ucx_default_allocator(), s, d, n);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
255 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
256
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
257 sstr_t* sstrsplit_a(UcxAllocator *allocator, sstr_t s, sstr_t d, ssize_t *n) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
258 if (s.length == 0 || d.length == 0) {
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
259 *n = -1;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 return NULL;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 }
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
262
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
263 /* special cases: delimiter is at least as large as the string */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
264 if (d.length >= s.length) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
265 /* exact match */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
266 if (sstrcmp(s, d) == 0) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
267 *n = 0;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
268 return NULL;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
269 } else /* no match possible */ {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
270 *n = 1;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
271 sstr_t *result = (sstr_t*) almalloc(allocator, sizeof(sstr_t));
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
272 *result = sstrdup_a(allocator, s);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
273 return result;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
274 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 }
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
276
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
277 ssize_t nmax = *n;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
278 size_t arrlen = 16;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
279 sstr_t* result = (sstr_t*) almalloc(allocator, arrlen*sizeof(sstr_t));
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
281 if (result) {
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
282 sstr_t curpos = s;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
283 ssize_t j = 1;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
284 while (1) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
285 sstr_t match;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
286 /* optimize for one byte delimiters */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
287 if (d.length == 1) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
288 match = curpos;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
289 for (size_t i = 0 ; i < curpos.length ; i++) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
290 if (curpos.ptr[i] == *(d.ptr)) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
291 match.ptr = curpos.ptr + i;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
292 break;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
293 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
294 match.length--;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
295 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
296 } else {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
297 match = sstrstr(curpos, d);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
298 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
299 if (match.length > 0) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
300 /* is this our last try? */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
301 if (nmax == 0 || j < nmax) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
302 /* copy the current string to the array */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
303 sstr_t item = sstrn(curpos.ptr, match.ptr - curpos.ptr);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
304 result[j-1] = sstrdup_a(allocator, item);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
305 size_t processed = item.length + d.length;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
306 curpos.ptr += processed;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
307 curpos.length -= processed;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
309 /* allocate memory for the next string */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
310 j++;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
311 if (j > arrlen) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
312 arrlen *= 2;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
313 sstr_t* reallocated = (sstr_t*) alrealloc(
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
314 allocator, result, arrlen*sizeof(sstr_t));
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
315 if (reallocated) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
316 result = reallocated;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
317 } else {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
318 for (ssize_t i = 0 ; i < j-1 ; i++) {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
319 alfree(allocator, result[i].ptr);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
320 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
321 alfree(allocator, result);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
322 *n = -2;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
323 return NULL;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
324 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
325 }
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
326 } else {
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
327 /* nmax reached, copy the _full_ remaining string */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
328 result[j-1] = sstrdup_a(allocator, curpos);
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
329 break;
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
330 }
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
331 } else {
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
332 /* no more matches, copy last string */
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
333 result[j-1] = sstrdup_a(allocator, curpos);
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
334 break;
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
335 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
336 }
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
337 *n = j;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
338 } else {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
339 *n = -2;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 return result;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 int sstrcmp(sstr_t s1, sstr_t s2) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
346 if (s1.length == s2.length) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
347 return memcmp(s1.ptr, s2.ptr, s1.length);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
348 } else if (s1.length > s2.length) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
349 return 1;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
350 } else {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
351 return -1;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
352 }
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354
39
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
355 int sstrcasecmp(sstr_t s1, sstr_t s2) {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
356 if (s1.length == s2.length) {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
357 #ifdef _WIN32
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
358 return _strnicmp(s1.ptr, s2.ptr, s1.length);
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
359 #else
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
360 return strncasecmp(s1.ptr, s2.ptr, s1.length);
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
361 #endif
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
362 } else if (s1.length > s2.length) {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
363 return 1;
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
364 } else {
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
365 return -1;
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
366 }
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
367 }
3e55bed345f9 added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
368
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 sstr_t sstrdup(sstr_t s) {
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
370 return sstrdup_a(ucx_default_allocator(), s);
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
371 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
372
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
373 sstr_t sstrdup_a(UcxAllocator *allocator, sstr_t s) {
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 sstr_t newstring;
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
375 newstring.ptr = (char*)almalloc(allocator, s.length + 1);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
376 if (newstring.ptr) {
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 newstring.length = s.length;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 newstring.ptr[newstring.length] = 0;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
379
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 memcpy(newstring.ptr, s.ptr, s.length);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
381 } else {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
382 newstring.length = 0;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
384
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385 return newstring;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386 }
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
387
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
388 sstr_t sstrtrim(sstr_t string) {
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
389 sstr_t newstr = string;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
390
81
8e186185422c UCX string module update
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
391 while (newstr.length > 0 && isspace(*newstr.ptr)) {
8e186185422c UCX string module update
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
392 newstr.ptr++;
8e186185422c UCX string module update
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
393 newstr.length--;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
394 }
81
8e186185422c UCX string module update
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
395 while (newstr.length > 0 && isspace(newstr.ptr[newstr.length-1])) {
8e186185422c UCX string module update
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
396 newstr.length--;
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
397 }
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
398
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
399 return newstr;
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
400 }
17
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
401
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
402 int sstrprefix(sstr_t string, sstr_t prefix) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
403 if (string.length == 0) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
404 return prefix.length == 0;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
405 }
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
406 if (prefix.length == 0) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
407 return 1;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
408 }
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
409
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
410 if (prefix.length > string.length) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
411 return 0;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
412 } else {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
413 return memcmp(string.ptr, prefix.ptr, prefix.length) == 0;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
414 }
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
415 }
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
416
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
417 int sstrsuffix(sstr_t string, sstr_t suffix) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
418 if (string.length == 0) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
419 return suffix.length == 0;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
420 }
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
421 if (suffix.length == 0) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
422 return 1;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
423 }
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
424
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
425 if (suffix.length > string.length) {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
426 return 0;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
427 } else {
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
428 return memcmp(string.ptr+string.length-suffix.length,
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
429 suffix.ptr, suffix.length) == 0;
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
430 }
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
431 }
174
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
432
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
433 sstr_t sstrlower(sstr_t string) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
434 sstr_t ret = sstrdup(string);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
435 for (size_t i = 0; i < ret.length ; i++) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
436 ret.ptr[i] = tolower(ret.ptr[i]);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
437 }
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
438 return ret;
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
439 }
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
440
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
441 sstr_t sstrlower_a(UcxAllocator *allocator, sstr_t string) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
442 sstr_t ret = sstrdup_a(allocator, string);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
443 for (size_t i = 0; i < ret.length ; i++) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
444 ret.ptr[i] = tolower(ret.ptr[i]);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
445 }
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
446 return ret;
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
447 }
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
448
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
449 sstr_t sstrupper(sstr_t string) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
450 sstr_t ret = sstrdup(string);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
451 for (size_t i = 0; i < ret.length ; i++) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
452 ret.ptr[i] = toupper(ret.ptr[i]);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
453 }
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
454 return ret;
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
455 }
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
456
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
457 sstr_t sstrupper_a(UcxAllocator *allocator, sstr_t string) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
458 sstr_t ret = sstrdup_a(allocator, string);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
459 for (size_t i = 0; i < ret.length ; i++) {
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
460 ret.ptr[i] = toupper(ret.ptr[i]);
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
461 }
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
462 return ret;
e7e56c56d126 updated ucx and used new sstrlower in util_header_callback
Mike Becker <universe@uap-core.de>
parents: 110
diff changeset
463 }

mercurial