MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / encoding_base91_encode

Function encoding_base91_encode

encoding/encoding.c:2132–2195  ·  view source on GitHub ↗

* @brief Encodes binary data into a Base91 encoded string. * * @param data Pointer to the binary data to be encoded. * @param length The length of the binary data. * * @return A dynamically allocated string containing the Base91 encoded representation. * Returns NULL if an error occurs (e.g., invalid input, memory allocation failure). * * @note The caller is responsible for freeing the r

Source from the content-addressed store, hash-verified

2130 size_t index = 0;
2131 int b = 0;
2132 int n = 0;
2133 int v;
2134
2135 for (size_t i = 0; i < length; ++i) {
2136 b |= (data[i] << n);
2137 n += 8;
2138
2139 if (n > 13) {
2140 v = b & 8191;
2141
2142 if (v > 88) {
2143 b >>= 13;
2144 n -= 13;
2145 }
2146 else {
2147 v = b & 16383;
2148 b >>= 14;
2149 n -= 14;
2150 }
2151
2152 if (index + 2 < estimated_length) {
2153 encoded[index++] = BASE91_ALPHABET[v % 91];
2154 encoded[index++] = BASE91_ALPHABET[v / 91];
2155 }
2156 else {
2157 ENCODING_LOG("[encoding_base91_encode] Error: Encoding index out of bounds");
2158 free(encoded);
2159 return NULL;
2160 }
2161 }
2162 }
2163
2164 if (n) {
2165 if (index + 1 < estimated_length) {
2166 encoded[index++] = BASE91_ALPHABET[b % 91];
2167 }
2168 if (n > 7 || b > 90) {
2169 if (index + 1 < estimated_length) {
2170 encoded[index++] = BASE91_ALPHABET[b / 91];
2171 }
2172 }
2173 }
2174
2175 encoded[index] = '\0';
2176 ENCODING_LOG("[encoding_base91_encode] Encoding completed successfully");
2177
2178 return encoded;
2179}
2180
2181
2182#if defined(_WIN32) || defined(_WIN64)
2183/**
2184 * @brief Converts a UTF-8 encoded string to a wide character string (wchar_t) on Windows.
2185 *
2186 * @param utf8Str Pointer to the UTF-8 encoded string.
2187 * @return A dynamically allocated wide character string (wchar_t*).
2188 * Returns NULL if the conversion fails or if the input string is NULL.
2189 */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected