@@ -1911,8 +1911,8 @@ void Helper::PrintHtmlTable(std::ostream& os, bool use_html, const std::vector<s
19111911 if (line[i].size () <= 64 ) {
19121912 os << brpc::min_width (line[i], min_widths[i]);
19131913 } else {
1914- os << " <div class=\" part\" >" << line[i].substr (0 , 64 ) << " ..." << " <span class= \" full \" > " << line[i]
1915- << " </span></div>" ;
1914+ os << " <div class=\" part\" >" << line[i].substr (0 , 64 ) << " ..."
1915+ << " <span class= \" full \" > " << line[i] << " < /span></div>" ;
19161916 }
19171917 }
19181918 } else {
@@ -2396,4 +2396,72 @@ void Helper::HandleBoolControlConfigVariable(const pb::common::ControlConfigVari
23962396 config.set_is_error_occurred (false );
23972397}
23982398
2399+ bool Helper::IsBase64Encoded (const std::string& input) {
2400+ if (input.length () % 4 != 0 ) {
2401+ return false ;
2402+ }
2403+
2404+ for (char c : input) {
2405+ if (!isalnum (c) && c != ' +' && c != ' /' && c != ' =' ) {
2406+ return false ;
2407+ }
2408+ }
2409+
2410+ size_t padding_count = 0 ;
2411+ for (size_t i = input.length (); i > 0 ; --i) {
2412+ if (input[i - 1 ] == ' =' ) {
2413+ padding_count++;
2414+ } else {
2415+ break ;
2416+ }
2417+ }
2418+ return padding_count <= 2 ;
2419+ }
2420+
2421+ std::string Helper::Base64Encode (const std::string& input) {
2422+ static const char base64_chars[] =
2423+ " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2424+ " abcdefghijklmnopqrstuvwxyz"
2425+ " 0123456789+/" ;
2426+ std::string encoded;
2427+ int val = 0 , valb = -6 ;
2428+ for (unsigned char c : input) {
2429+ val = (val << 8 ) + c;
2430+ valb += 8 ;
2431+ while (valb >= 0 ) {
2432+ encoded.push_back (base64_chars[(val >> valb) & 0x3F ]);
2433+ valb -= 6 ;
2434+ }
2435+ }
2436+ if (valb > -6 ) {
2437+ encoded.push_back (base64_chars[((val << 8 ) >> (valb + 8 )) & 0x3F ]);
2438+ }
2439+ while (encoded.size () % 4 ) {
2440+ encoded.push_back (' =' );
2441+ }
2442+ return encoded;
2443+ }
2444+
2445+ std::string Helper::EncodeREContent (const std::string& input) {
2446+ std::regex re_pattern (R"( RE\s*\[((?:[^\[\]]|\[.*?\])*)\])" );
2447+ std::smatch matches;
2448+ std::string result = input;
2449+ std::string::const_iterator search_start (input.cbegin ());
2450+
2451+ while (std::regex_search (search_start, input.cend (), matches, re_pattern)) {
2452+ std::string matched_text = matches[0 ];
2453+ std::string content = matches[1 ];
2454+
2455+ if (!IsBase64Encoded (content)) {
2456+ std::string encoded_content = Base64Encode (content);
2457+ std::string replacement = " RE [" + encoded_content + " ]" ;
2458+ result.replace (matches.position (0 ), matched_text.length (), replacement);
2459+ }
2460+
2461+ search_start = matches.suffix ().first ;
2462+ }
2463+
2464+ return result;
2465+ }
2466+
23992467} // namespace dingodb
0 commit comments