少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "il2cpp-config.h"
#include <memory>
#include "il2cpp-object-internals.h"
#include "il2cpp-class-internals.h"
#include "icalls/mscorlib/System.Globalization/CompareInfo.h"
#include "icalls/mscorlib/System.Globalization/CompareOptions.h"
#include "vm/String.h"
#include "vm/Exception.h"
#include "vm/Array.h"
#include "utils/StringUtils.h"
#include "vm-utils/VmStringUtils.h"
#include <cwctype>
#include <wctype.h>
 
namespace il2cpp
{
namespace icalls
{
namespace mscorlib
{
namespace System
{
namespace Globalization
{
    void CompareInfo::free_internal_collator(mscorlib_System_Globalization_CompareInfo * thisPtr)
    {
        // This method does not need any implementation.
    }
 
    static int string_invariant_indexof(Il2CppString *source, int sindex, int count, Il2CppString *value, bool first)
    {
        int lencmpstr = il2cpp::utils::StringUtils::GetLength(value);
        Il2CppChar* src = il2cpp::utils::StringUtils::GetChars(source);
        Il2CppChar* cmpstr = il2cpp::utils::StringUtils::GetChars(value);
 
        if (first)
        {
            count -= lencmpstr;
            for (int pos = sindex; pos <= sindex + count; pos++)
            {
                for (int i = 0; src[pos + i] == cmpstr[i];)
                {
                    if (++i == lencmpstr)
                        return (pos);
                }
            }
 
            return (-1);
        }
        else
        {
            for (int pos = sindex - lencmpstr + 1; pos > sindex - count; pos--)
            {
                if (memcmp(src + pos, cmpstr, lencmpstr * sizeof(Il2CppChar)) == 0)
                    return (pos);
            }
 
            return (-1);
        }
    }
 
    int CompareInfo::internal_index(mscorlib_System_Globalization_CompareInfo *thisPtr, Il2CppString *source, int sindex, int count, Il2CppString *value, int options, bool first)
    {
        return (string_invariant_indexof(source, sindex, count, value, first));
    }
 
    static int string_invariant_compare_char(Il2CppChar c1, Il2CppChar c2, int options)
    {
        int result = 0;
 
        // Ordinal can not be mixed with other options, and must return the difference, not only -1, 0, 1.
        if (options & CompareOptions_Ordinal)
            return (int)(c1 - c2);
 
        if (options & CompareOptions_IgnoreCase)
        {
            result = towlower(c1) - towlower(c2);
        }
        else
        {
            /*
             * No options. Kana, symbol and spacing options don't
             * apply to the invariant culture.
             */
 
            /*
             * FIXME: here we must use the information from c1type and c2type
             * to find out the proper collation, even on the InvariantCulture, the
             * sorting is not done by computing the unicode values, but their
             * actual sort order.
             */
            result = (int)(c1 - c2);
        }
 
        return ((result < 0) ? -1 : (result > 0) ? 1 : 0);
    }
 
    static int string_invariant_compare(Il2CppString *str1, int off1, int len1, Il2CppString *str2, int off2, int len2, int options)
    {
        int length;
        if (len1 >= len2)
            length = len1;
        else
            length = len2;
 
        Il2CppChar* ustr1 = il2cpp::utils::StringUtils::GetChars(str1) + off1;
        Il2CppChar* ustr2 = il2cpp::utils::StringUtils::GetChars(str2) + off2;
 
        int pos = 0;
        for (pos = 0; pos != length; pos++)
        {
            if (pos >= len1 || pos >= len2)
                break;
 
            int charcmp = string_invariant_compare_char(ustr1[pos], ustr2[pos], options);
            if (charcmp != 0)
                return (charcmp);
        }
 
        // The lesser wins, so if we have looped until length we just need to check the last char.
        if (pos == length)
            return (string_invariant_compare_char(ustr1[pos - 1], ustr2[pos - 1], options));
 
        // Test if one of the strings has been compared to the end.
        if (pos >= len1)
        {
            if (pos >= len2)
                return (0);
            else
                return (-1);
        }
        else if (pos >= len2)
            return (1);
 
        // If not, check our last char only.. (can this happen?)
        return (string_invariant_compare_char(ustr1[pos], ustr2[pos], options));
    }
 
    int CompareInfo::internal_compare(mscorlib_System_Globalization_CompareInfo *thisPtr, Il2CppString *str1, int off1, int len1, Il2CppString *str2, int off2, int len2, int options)
    {
        //MONO_ARCH_SAVE_REGS;
 
        // Do a normal ascii string compare, as we only know the invariant locale if we dont have ICU.
        return (string_invariant_compare(str1, off1, len1, str2, off2, len2, options));
    }
 
    void CompareInfo::construct_compareinfo(mscorlib_System_Globalization_CompareInfo *, Il2CppString *)
    {
        // This method does not need any implementation.
    }
 
    static Il2CppArray* GetSortKeyCaseSensitive(Il2CppString* source)
    {
        const int32_t keyLength = sizeof(Il2CppChar) * source->length;
        Il2CppArray* keyBytes = vm::Array::New(il2cpp_defaults.byte_class, keyLength);
        memcpy(il2cpp_array_addr(keyBytes, uint8_t, 0), source->chars, keyLength);
 
        return keyBytes;
    }
 
    static Il2CppArray* GetSortKeyIgnoreCase(Il2CppString* source)
    {
        const int32_t keyLength = sizeof(Il2CppChar) * source->length;
        Il2CppArray* keyBytes = vm::Array::New(il2cpp_defaults.byte_class, keyLength);
        Il2CppChar* destination = reinterpret_cast<Il2CppChar*>(il2cpp_array_addr(keyBytes, uint8_t, 0));
 
        for (int i = 0; i < source->length; i++, destination++)
        {
            *destination = utils::VmStringUtils::Utf16ToLower(source->chars[i]);
        }
 
        return keyBytes;
    }
 
    void CompareInfo::assign_sortkey(void* /* System.Globalization.CompareInfo */ self, Il2CppSortKey* key, Il2CppString* source, CompareOptions options)
    {
        if ((options & CompareOptions_IgnoreCase) != 0 || (options & CompareOptions_OrdinalIgnoreCase) != 0)
        {
            key->key = GetSortKeyIgnoreCase(source);
        }
        else
        {
            key->key = GetSortKeyCaseSensitive(source);
        }
    }
} /* namespace Globalization */
} /* namespace System */
} /* namespace mscorlib */
} /* namespace icalls */
} /* namespace il2cpp */