acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_template.h
1// Created by camilo on 2025-09-11 03:04 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5template < prototype_character CHARACTER >
6inline character_count _string_get_length2(const CHARACTER * psz, character_count lengthMax) noexcept
7{
8
9 character_count size = 0;
10
11 while (lengthMax > 0 && *psz)
12 {
13
14 psz++;
15
16 size++;
17
18 lengthMax--;
19
20 }
21
22 return size;
23
24}
25
26
27template<typename CHARACTER>
28inline character_count __utftype_to_utftype_len(const CHARACTER *psz)
29{
30
31 auto p = psz;
32
33 while (*p)
34 {
35
36 p = unicode_next(p);
37
38 if (!p)
39 {
40
41 throw_encoding_exception("__utftype_to_utftype_len");
42
43 }
44
45 }
46
47 return p - psz;
48
49}
50
51
52template<typename CHARACTER, typename CHARACTER_COUNT>
53inline character_count __utftype_to_utftype_len2(const CHARACTER *psz, CHARACTER_COUNT & srclen)
54{
55
56 if (srclen < 0)
57 {
58
59 return __utftype_to_utftype_len(psz);
60
61 }
62
63 auto p = psz;
64
65 character_count countSrc = 0;
66
67 auto remainingSrc = srclen;
68
69 while (countSrc < srclen && *p)
70 {
71
72 auto pNext = unicode_next(p, &remainingSrc);
73
74 auto len = pNext - p;
75
76 if (countSrc + len > srclen)
77 {
78
79 throw_encoding_exception("__utftype_to_utftype_len2");
80
81 }
82
83 p = pNext;
84
85 countSrc += len;
86
87 }
88
89 return countSrc;
90
91}
92
93
94