mirror of
https://github.com/Syping/dtranslatebot.git
synced 2025-09-06 00:42:06 +02:00
add Boost.Regex support
This commit is contained in:
parent
5b9c3ce38f
commit
9f995a129c
3 changed files with 65 additions and 6 deletions
43
src/regex.h
Normal file
43
src/regex.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*****************************************************************************
|
||||
* dtranslatebot Discord Translate Bot
|
||||
* Copyright (C) 2023-2024 Syping
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* This software is provided as-is, no warranties are given to you, we are not
|
||||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef REGEX_H
|
||||
#define REGEX_H
|
||||
|
||||
#ifdef DTRANSLATEBOT_USE_BOOST_REGEX
|
||||
#include <boost/regex.hpp>
|
||||
#else
|
||||
#include <regex>
|
||||
#endif
|
||||
#include <string_view>
|
||||
|
||||
namespace bot {
|
||||
#ifdef DTRANSLATEBOT_USE_BOOST_REGEX
|
||||
using boost::regex;
|
||||
using boost::regex_match;
|
||||
using boost::match_results;
|
||||
typedef boost::match_results<std::string_view::const_iterator> svmatch;
|
||||
#else
|
||||
using std::regex;
|
||||
using std::regex_match;
|
||||
using std::match_results;
|
||||
typedef std::match_results<std::string_view::const_iterator> svmatch;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // REGEX_H
|
|
@ -17,7 +17,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <future>
|
||||
#include <regex>
|
||||
#include "regex.h"
|
||||
#include "webhook_push.h"
|
||||
using namespace std::string_literals;
|
||||
using namespace std::string_view_literals;
|
||||
|
@ -40,16 +40,16 @@ void bot::webhook_push::run(const bot::translated_message &message, dpp::cluster
|
|||
message_v = message_v.substr(1333 + pos);
|
||||
}
|
||||
else {
|
||||
std::match_results<std::string_view::const_iterator> match;
|
||||
if (std::regex_match(message_eov.begin(), message_eov.end(), match, std::regex("^.*(\\.|\\?|\\!|\\。)\\s.*$"s))) {
|
||||
bot::svmatch match;
|
||||
if (bot::regex_match(message_eov.begin(), message_eov.end(), match, bot::regex("^.*(\\.|\\?|\\!|\\。)\\s.*$"s))) {
|
||||
json_body["content"] = message_v.substr(0, 1334 + match.position(1));
|
||||
message_v = message_v.substr(1334 + match.position(1));
|
||||
}
|
||||
else if (std::regex_match(message_eov.begin(), message_eov.end(), match, std::regex("^.*(\\,)\\s.*$"s))) {
|
||||
else if (bot::regex_match(message_eov.begin(), message_eov.end(), match, bot::regex("^.*(\\,)\\s.*$"s))) {
|
||||
json_body["content"] = message_v.substr(0, 1334 + match.position(1));
|
||||
message_v = message_v.substr(1334 + match.position(1));
|
||||
}
|
||||
else if (std::regex_match(message_eov.begin(), message_eov.end(), match, std::regex("^.*()\\s.*$"s))) {
|
||||
else if (bot::regex_match(message_eov.begin(), message_eov.end(), match, bot::regex("^.*()\\s.*$"s))) {
|
||||
json_body["content"] = message_v.substr(0, 1334 + match.position(1));
|
||||
message_v = message_v.substr(1334 + match.position(1));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue