Skip to content

Commit

Permalink
hotplace rev.546 grooming
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Jun 30, 2024
1 parent 33225ae commit 71cb201
Show file tree
Hide file tree
Showing 32 changed files with 1,723 additions and 1,206 deletions.
4 changes: 3 additions & 1 deletion sdk/base/basic/huffman_coding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ huffman_coding &huffman_coding::operator<<(const char *s) { return load(s); }
huffman_coding &huffman_coding::load(const char *s) {
// count
if (s) {
auto hook = [](hc_t &t) -> void { t.weight++; };
for (const char *p = s; *p; p++) {
_measure.insert(hc_t((uint8)*p), [](hc_t &t) -> void { t.weight++; });
uint8 symbol = (uint8)*p;
_measure.insert(hc_t(symbol), hook);
}
}
return *this;
Expand Down
39 changes: 34 additions & 5 deletions sdk/base/basic/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdarg.h>

#include <ostream>
#include <sdk/base/basic/base16.hpp>
#include <sdk/base/basic/ieee754.hpp>
#include <sdk/base/basic/template.hpp>
#include <sdk/base/basic/variant.hpp>
Expand Down Expand Up @@ -368,16 +369,44 @@ variant &variant::set_binary_new(const binary_t &bin) {
return *this;
}

const std::string variant::to_str() const {
std::string ret_value;
to_string(ret_value);
return ret_value;
}

const std::string variant::to_hex() const {
binary_t bin;
std::string ret_value;
to_binary(bin);
base16_encode(bin, ret_value);
return ret_value;
}

const binary_t variant::to_bin() const {
binary_t bin;
to_binary(bin);
return bin;
}

int variant::to_int() const { return t_to_int<int>(_vt); }

return_t variant::to_binary(binary_t &target) const {
return_t ret = errorcode_t::success;

if (TYPE_BINARY == _vt.type) {
target.clear();
binary_append(target, _vt.data.bstr, _vt.size);
} else {
ret = errorcode_t::mismatch;
switch (_vt.type) {
case TYPE_BINARY:
case TYPE_NSTRING:
target.clear();
binary_append(target, _vt.data.bstr, _vt.size);
break;
case TYPE_STRING:
target.clear();
binary_append(target, _vt.data.str);
break;
default:
ret = errorcode_t::mismatch;
break;
}
return ret;
}
Expand Down
3 changes: 3 additions & 0 deletions sdk/base/basic/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class variant {
variant& set_nstr_new(const char* value, size_t n);
variant& set_binary_new(const binary_t& bin);

const std::string to_str() const;
const std::string to_hex() const;
const binary_t to_bin() const;
int to_int() const;
return_t to_binary(binary_t& target) const;
return_t to_string(std::string& target) const;
Expand Down
2 changes: 1 addition & 1 deletion sdk/base/nostd/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <list>
#include <map>
#include <queue>
#include <sdk/base/nostd/container.hpp>
#include <sdk/base/nostd/template.hpp>
#include <sdk/base/stream/basic_stream.hpp>
#include <sdk/base/syntax.hpp>
#include <sdk/base/types.hpp>
Expand Down
1 change: 1 addition & 0 deletions sdk/base/nostd/pattern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef __HOTPLACE_SDK_BASE_NOSTD_PATTERN__
#define __HOTPLACE_SDK_BASE_NOSTD_PATTERN__

#include <functional>
#include <sdk/base/error.hpp>
#include <sdk/base/syntax.hpp>
#include <sdk/base/types.hpp>
Expand Down
File renamed without changes.
28 changes: 8 additions & 20 deletions sdk/base/string/string_charset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>

#include <list>
#include <sdk/base/nostd/pattern.hpp>
#include <sdk/base/string/string.hpp>
#include <string>

Expand Down Expand Up @@ -82,27 +83,14 @@ return_t scan(const wchar_t* stream, size_t sizestream, size_t startpos, size_t*
__leave2;
}

const TCHAR* pos = stream + startpos;
const TCHAR* epos = stream + sizestream;
const TCHAR* p = stream + startpos;

#if defined _MBCS || defined MBCS
size_t sizetoken = strlen(match);
while ((0 != strnicmp(match, p, sizetoken)) && p < epos) {
p++;
}
#elif defined _UNICODE || defined UNICODE
size_t sizetoken = wcslen(match);
while ((0 != wcsnicmp(match, p, sizetoken)) && p < epos) {
p++;
}
#endif

if (p < epos) {
*brk = startpos + p - pos + 1;
} else {
t_kmp_pattern<TCHAR> kmp;
size_t sizematch = _tcslen(match);
int pos = kmp.match(stream, sizestream, match, sizematch, startpos);
if (-1 == pos) {
*brk = sizestream;
// ret = errorcode_t::not_found;
ret = errorcode_t::not_found;
} else {
*brk = pos + 1;
}
}
__finally2 {
Expand Down
19 changes: 14 additions & 5 deletions sdk/base/template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,29 @@ struct t_type_comparator : t_comparator_base<T> {
* // -170141183460469231731687303715884105728 80000000000000000000000000000000
*/
template <typename TYPE>
TYPE t_atoi(const std::string& in) {
TYPE t_atoi_n(const char* value, size_t size) {
return_t ret = errorcode_t::success;
TYPE res = 0;

__try2 {
if (nullptr == value) {
__leave2;
}

size_t i = 0;
int sign = 0;

if (in[i] == '-') {
if (value[i] == '-') {
++i;
sign = -1;
}

if (in[i] == '+') {
if (value[i] == '+') {
++i;
}

for (; i < in.size(); ++i) {
const char c = in[i];
for (; i < size; ++i) {
const char c = value[i];
if (not std::isdigit(c)) {
ret = errorcode_t::bad_data;
break;
Expand All @@ -91,6 +95,11 @@ TYPE t_atoi(const std::string& in) {
return res;
}

template <typename TYPE>
TYPE t_atoi(const std::string& value) {
return t_atoi_n<TYPE>(value.c_str(), value.size());
}

/**
* @return unsigned integer value
* @sa t_atoi for signed/unsigned
Expand Down
2 changes: 1 addition & 1 deletion sdk/crypto/jose/json_object_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ return_t json_object_encryption::doencrypt(jose_context_t *handle, jwe_t enc, jw

uint32 enc_group = enc_hint->group;
if (jwe_group_t::jwe_group_aescbc_hs == enc_group) {
// // RFC 7516 Appendix B. Example AES_128_CBC_HMAC_SHA_256 Computation
// RFC 7516 Appendix B. Example AES_128_CBC_HMAC_SHA_256 Computation
openssl_aead aead;
ret = aead.aes_cbc_hmac_sha2_encrypt(enc_crypt_alg, enc_crypt_mode, enc_hash_alg, cek, iv, aad, input, ciphertext, tag);
} else if (jwe_group_t::jwe_group_aesgcm == enc_group) {
Expand Down
Loading

0 comments on commit 71cb201

Please sign in to comment.