Skip to content

Commit e0c6c75

Browse files
committed
Обновлена используемая версия simstr.
1 parent 39b5187 commit e0c6c75

4 files changed

Lines changed: 19 additions & 32 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include(FetchContent)
55

66
project(
77
simjson
8-
VERSION 1.2.2
8+
VERSION 1.2.3
99
DESCRIPTION "Very simple json library"
1010
HOMEPAGE_URL "https://github.com/orefkov/simjson"
1111
LANGUAGES CXX
@@ -67,7 +67,7 @@ function(add_simstr)
6767
simstr
6868
GIT_REPOSITORY https://github.com/orefkov/simstr.git
6969
GIT_SHALLOW TRUE
70-
GIT_TAG 458007e
70+
GIT_TAG tags/rel1.2.6
7171
FIND_PACKAGE_ARGS NAMES simstr
7272
)
7373
FetchContent_MakeAvailable(simstr)

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
Designed to work with JSON when using the [simstr](https://github.com/orefkov/simstr) library.
55

6-
Version 1.2.2.
6+
Version 1.2.3.
77

88
<span class="obfuscator"><a href="readme_ru.md">On Russian | По-русски</a></span>
99

1010
This library contains a simple implementation of a simple JsonValue object for working with JSON using string objects
1111
of the *simstr* library, since other libraries mainly work with `std::string` or raw `const char*`.
1212
The task was not to somehow compete in performance or optimality with other libraries, I mainly use it
13-
for working with small config files - read, modify, write.
13+
for working with small config files - read, modify, write. However, it also copes quite well with large files.
1414

1515
For json objects, `std::unordered_map` is used, in the form of `hashStrMap<K, JsonValueTemp<K>>`,
1616
for arrays - `std::vector<JsonValueTemp<K>>`, strings are stored in `sstring<K>`.
@@ -50,7 +50,7 @@ downloads automatically).
5050
// Simple json, equal to 1.
5151
JsonValue json = 1; // int64
5252
stringa text = json.store(); // "1"
53-
53+
5454
// Initialization of the object, ""_h - slightly optimizes the key, calculating the hash during compilation
5555
JsonValue obj = {
5656
{"Key1"_h, 1},
@@ -67,7 +67,7 @@ downloads automatically).
6767
// Saving keys, immediately several levels
6868
test["a"_h]["b"_h]["c"_h] = 10;
6969
text = json.store(); // {"a":{"b":{"c":10}}}
70-
70+
7171
// Converts a json object to an array
7272
test[0] = "value";
7373
test[-1] = true; // When using -1 - the value is added to the end of the array
@@ -114,9 +114,9 @@ void read_config_from_file(ssa folder, ssa file_name) {
114114
stringa config;
115115
if (is_file_exist(fullPath)) {
116116
config = get_file_content(fullPath);
117-
117+
118118
auto [readed, error, line, col] = JsonValue::parse(config);
119-
119+
120120
if (error != JsonParseResult::Success) {
121121
std::cerr << "Error in parse config file " << fullPath <<
122122
" at line " << line << ", col " << col << std::endl;

readme_ru.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
Предназначена для работы с JSON при использовании библиотеки [simstr](https://github.com/orefkov/simstr).
55

6-
Версия 1.2.2.
6+
Версия 1.2.3.
77

88
<span class="obfuscator"><a href="readme.md">On English | По-английски</a></span>
99

1010
В этой библиотеке содержится простая реализация простого объекта JsonValue для работы с JSON с использованием строковых объектов
1111
библиотеки *simstr*, так как другие библиотеки работают в основном с `std::string` или сырыми `const char*`.
12-
Задача как-то соревноваться по производительности или оптимальности с другими библиотеками не ставилась, я её применяю в-основном
13-
для работы с небольшими конфиг-файлами - прочитать, изменить, записать.
12+
Задача как-то соревноваться по производительности или оптимальности с другими библиотеками не ставилась, я её применяю в-основном
13+
для работы с небольшими конфиг-файлами - прочитать, изменить, записать, однако и с большими файлами она вполне успешно справляется.
1414

1515
Для json-объектов используется `std::unordered_map`, в лице `hashStrMap<K, JsonValueTemp<K>>`,
1616
для массивов - `std::vector<JsonValueTemp<K>>`, строки хранятся в `sstring<K>`.
@@ -50,7 +50,7 @@
5050
// Простой json, равный 1.
5151
JsonValue json = 1; // int64
5252
stringa text = json.store(); // "1"
53-
53+
5454
// Инициализация объекта, ""_h - несколько оптимизирует ключ, вычисляя хэш при компиляции
5555
JsonValue obj = {
5656
{"Key1"_h, 1},
@@ -67,7 +67,7 @@
6767
// Сохраняем ключи, сразу несколько уровней
6868
test["a"_h]["b"_h]["c"_h] = 10;
6969
text = json.store(); // {"a":{"b":{"c":10}}}
70-
70+
7171
// Преобразует json-объект в массив
7272
test[0] = "value";
7373
test[-1] = true; // При использовании -1 - значение добавляется в конец массива
@@ -114,9 +114,9 @@ void read_config_from_file(ssa folder, ssa file_name) {
114114
stringa config;
115115
if (is_file_exist(fullPath)) {
116116
config = get_file_content(fullPath);
117-
117+
118118
auto [readed, error, line, col] = JsonValue::parse(config);
119-
119+
120120
if (error != JsonParseResult::Success) {
121121
std::cerr << "Error in parse config file " << fullPath <<
122122
" at line " << line << ", col " << col << std::endl;

src/json.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,9 @@ SIMJSON_API std::optional<int64_t> JsonValueTempl<K>::to_integer() const {
260260
return res;
261261
}
262262
if (processed > 0 && err == IntConvertResult::BadSymbolAtTail &&
263-
(txt[processed] == '.' || txt[processed] == 'e' || txt[processed] == 'E')) {
263+
(txt[processed] == '.' || (txt[processed] | 0x20) == 'e')) {
264264
// Считаем, что в тексте double
265-
auto dbl = std::nan("");
266-
if constexpr (is_one_of_std_char_v<K>) {
267-
dbl = txt.to_double();
268-
} else {
269-
dbl = lstringa<100>{txt}.to_double();
270-
}
265+
auto dbl = txt.to_double().value_or(std::nan("0"));
271266
if (is_double_int64(dbl)) {
272267
return static_cast<int64_t>(dbl);
273268
}
@@ -301,11 +296,7 @@ SIMJSON_API double JsonValueTempl<K>::to_real() const {
301296
case Json::Boolean:
302297
return val_.boolean ? 1.0 : 0.0;
303298
case Json::Text:
304-
if constexpr (is_one_of_std_char_v<K>) {
305-
return val_.text.to_double();
306-
} else {
307-
return lstringa<100>{val_.text}.to_double();
308-
}
299+
return val_.text.to_double().value_or(std::nan("0"));
309300
case Json::Integer:
310301
return static_cast<double>(val_.integer);
311302
case Json::Real:
@@ -1120,11 +1111,7 @@ JsonValueTempl<K>* StreamedJsonParser<K>::addNumber(JsonValueTempl<K>* current)
11201111
}
11211112

11221113
if (!asInt || jsonValue.is_undefined()) {
1123-
if constexpr (is_one_of_std_char_v<K>) {
1124-
jsonValue = ssValue.to_double();
1125-
} else {
1126-
jsonValue = lstringa<100>(ssValue).to_double();
1127-
}
1114+
jsonValue = ssValue.to_double().value_or(std::nan("0"));
11281115
}
11291116

11301117
if constexpr (!All) {

0 commit comments

Comments
 (0)