-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
285 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <regex> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "Logger.hpp" | ||
#include "Collections.hpp" | ||
|
||
int main(const int argc, const char * const argv[]) { | ||
lifuren::logger::init(); | ||
SPDLOG_DEBUG("测试"); | ||
std::vector<std::string> vector; | ||
SPDLOG_DEBUG("join:{}", lifuren::collections::join(vector, ",")); | ||
vector.push_back("1"); | ||
vector.push_back("2"); | ||
vector.push_back("3"); | ||
SPDLOG_DEBUG("join:{}", lifuren::collections::join(vector, ",")); | ||
std::vector<std::string> split = lifuren::collections::split("", ","); | ||
assert(split.size() == 1); | ||
split = lifuren::collections::split("1", ","); | ||
assert(split.size() == 1); | ||
split = lifuren::collections::split(",,", ","); | ||
assert(split.size() == 3); | ||
split = lifuren::collections::split("1,", ","); | ||
assert(split.size() == 2); | ||
split = lifuren::collections::split(",1", ","); | ||
assert(split.size() == 2); | ||
split = lifuren::collections::split(",1,", ","); | ||
assert(split.size() == 3); | ||
split = lifuren::collections::split("1,2", ","); | ||
assert(split.size() == 2); | ||
split = lifuren::collections::split(",1,2", ","); | ||
assert(split.size() == 3); | ||
split = lifuren::collections::split("1,2,", ","); | ||
assert(split.size() == 3); | ||
split = lifuren::collections::split(",1,2,", ","); | ||
assert(split.size() == 4); | ||
split = lifuren::collections::split("1,2", ","); | ||
assert(split.size() == 2); | ||
split = lifuren::collections::split("", std::vector<std::string>{ ",", "。" }); | ||
assert(split.size() == 1); | ||
split = lifuren::collections::split("1", std::vector<std::string>{ ",", "。" }); | ||
assert(split.size() == 1); | ||
split = lifuren::collections::split(",1", std::vector<std::string>{ ",", "。" }); | ||
assert(split.size() == 2); | ||
split = lifuren::collections::split("1,", std::vector<std::string>{ ",", "。" }); | ||
assert(split.size() == 2); | ||
split = lifuren::collections::split(",1,", std::vector<std::string>{ ",", "。" }); | ||
assert(split.size() == 3); | ||
split = lifuren::collections::split("1,2。3", std::vector<std::string>{ ",", "。" }); | ||
assert(split.size() == 3); | ||
split = lifuren::collections::split("。1,2。3。", std::vector<std::string>{ ",", "。" }); | ||
assert(split.size() == 5); | ||
SPDLOG_DEBUG("完成"); | ||
lifuren::logger::shutdown(); | ||
return 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <regex> | ||
#include <string> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
#include "Logger.hpp" | ||
#include "Strings.hpp" | ||
#include "Collections.hpp" | ||
|
||
#include "nlohmann/json.hpp" | ||
|
||
int main(const int argc, const char * const argv[]) { | ||
lifuren::logger::init(); | ||
SPDLOG_DEBUG("测试"); | ||
const std::string content = lifuren::strings::trim(R"( | ||
庭院深深深几许,杨柳堆烟,帘幕无重数。玉勒雕鞍游冶处,楼高不见章台路。 | ||
雨横风狂三月暮,门掩黄昏,无计留春住。泪眼问花花不语,乱红飞过秋千去。 | ||
)"); | ||
int fontSize = 0; | ||
int segmentSize = 0; | ||
std::vector<int> segmentFontSize; | ||
nlohmann::json json; | ||
std::vector<std::string> vector = lifuren::collections::split(content, std::vector<std::string>{ ",", "。", "?", "!" }); | ||
std::for_each(vector.begin(), vector.end(), [&fontSize, &segmentSize, &segmentFontSize](auto& segment) { | ||
segment = lifuren::strings::trim(segment); | ||
if(segment.empty()) { | ||
return; | ||
} | ||
SPDLOG_DEBUG("诗句:{}", segment); | ||
int length = lifuren::strings::length(segment.c_str()); | ||
fontSize += length; | ||
segmentSize++; | ||
segmentFontSize.push_back(length); | ||
}); | ||
SPDLOG_DEBUG("诗句字数:{}", fontSize); | ||
SPDLOG_DEBUG("诗句段数:{}", segmentSize); | ||
SPDLOG_DEBUG("逐句字数:{}", lifuren::collections::join(segmentFontSize, ",")); | ||
json["example"] = content; | ||
json["fontSize"] = fontSize; | ||
json["segmentSize"] = segmentSize; | ||
json["segmentRule"] = segmentFontSize; | ||
json["participleRule"] = std::vector<int>{ }; | ||
SPDLOG_DEBUG("配置规则:{}", json.dump(2)); | ||
SPDLOG_DEBUG("完成"); | ||
lifuren::logger::shutdown(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
{ | ||
"诗词标题": { | ||
"fontSize": 28, | ||
"segmentSize": 4, | ||
"segmentRule": [ 7, 7, 7, 7 ], | ||
"participleRule": [ 7, 7, 7, 7 ] | ||
"虞美人·春花秋月何时了": { | ||
"example": "春花秋月何时了,往事知多少?小楼昨夜又东风,故国不堪回首月明中。\n雕栏玉砌应犹在,只是朱颜改。问君能有几多愁?恰似一江春水向东流。", | ||
"fontSize": 56, | ||
"segmentRule": [ 7, 5, 7, 9, 7, 5, 7, 9 ], | ||
"segmentSize": 8, | ||
"participleRule": [ | ||
2, 2, 3, 2, 3, 2, 2, 3, 2, 2, 2, 3, | ||
2, 2, 3, 2, 3, 2, 2, 3, 2, 2, 2, 3 | ||
] | ||
}, | ||
"蝶恋花·庭院深深深几许": { | ||
"example": "庭院深深深几许,杨柳堆烟,帘幕无重数。玉勒雕鞍游冶处,楼高不见章台路。\n雨横风狂三月暮,门掩黄昏,无计留春住。泪眼问花花不语,乱红飞过秋千去。", | ||
"fontSize": 60, | ||
"segmentRule": [ 7, 4, 5, 7, 7, 7, 4, 5, 7, 7 ], | ||
"segmentSize": 10, | ||
"participleRule": [ | ||
2, 2, 3, 2, 2, 2, 3, 2, 2, 3, 2, 2, 3, | ||
2, 2, 3, 2, 2, 2, 3, 2, 2, 3, 2, 2, 3 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* 集合 | ||
* | ||
* @author acgist | ||
*/ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <list> | ||
#include <vector> | ||
#include <string> | ||
|
||
namespace lifuren { | ||
namespace collections { | ||
|
||
/** | ||
* @param collection 集合 | ||
* @param delim 分隔符号 | ||
* | ||
* @return 拼接内容 | ||
*/ | ||
template <typename T> | ||
std::string join(T& collection, const std::string& delim) { | ||
std::string ret; | ||
if(collection.empty()) { | ||
return ret; | ||
} | ||
T::iterator iter = collection.begin(); | ||
const T::const_iterator end = collection.end(); | ||
const T::const_iterator last = collection.end() - 1; | ||
for (; iter != end; ++iter) { | ||
ret += std::to_string(*iter); | ||
if (iter != last) { | ||
ret += delim; | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
/** | ||
* @param content 文本内容 | ||
* @param delim 分隔符号 | ||
* | ||
* @return 分割列表 | ||
*/ | ||
extern std::vector<std::string> split(const std::string& content, const std::string& delim); | ||
|
||
/** | ||
* @param content 文本内容 | ||
* @param multi 分隔符号 | ||
* | ||
* @return 分割列表 | ||
*/ | ||
extern std::vector<std::string> split(const std::string& content, const std::vector<std::string>& multi); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "Collections.hpp" | ||
|
||
std::vector<std::string> lifuren::collections::split(const std::string& content, const std::string& delim) { | ||
std::vector<std::string> vector; | ||
size_t pos = 0; | ||
size_t index = 0; | ||
while(true) { | ||
pos = content.find(delim, index); | ||
if(pos == std::string::npos) { | ||
break; | ||
} | ||
vector.push_back(content.substr(index, pos - index)); | ||
index = pos + delim.length(); | ||
} | ||
if(pos != index && index <= content.length()) { | ||
vector.push_back(content.substr(index, content.length() - index)); | ||
} | ||
return vector; | ||
} | ||
|
||
std::vector<std::string> lifuren::collections::split(const std::string& content, const std::vector<std::string>& multi) { | ||
std::vector<std::string> vector; | ||
size_t pos = 0; | ||
size_t index = 0; | ||
std::string delim; | ||
while(true) { | ||
size_t min = std::string::npos; | ||
for(auto& value : multi) { | ||
pos = content.find(value, index); | ||
if(pos != std::string::npos && pos < min) { | ||
min = pos; | ||
delim = value; | ||
} | ||
} | ||
pos = min; | ||
if(pos == std::string::npos) { | ||
break; | ||
} | ||
vector.push_back(content.substr(index, pos - index)); | ||
index = pos + delim.length(); | ||
} | ||
if(pos != index && index <= content.length()) { | ||
vector.push_back(content.substr(index, content.length() - index)); | ||
} | ||
return vector; | ||
} |