summaryrefslogtreecommitdiff
path: root/src/string_utils.cc
AgeCommit message (Collapse)Author
2024-08-19Merge remote-tracking branch 'arrufat/includes-cleanup'Maxime Coste
2024-08-16include headers cleanupAdriĆ  Arrufat
2024-08-14Remove unused wrap_to and reduce string_utils headersMaxime Coste
2024-08-14More include fixesMaxime Coste
2024-08-12Extract format implementation to its own fileMaxime Coste
Split it to avoid pulling all string_utils dependencies for just format.
2024-06-23Fix trailing whitespacesMaxime Coste
2023-11-03Add support for 0-padding in format and replace uses of sprintfMaxime Coste
2023-11-03Use explicit target types for gather calls to bypass clang regressionMaxime Coste
Since clang-16 there has been a regression in the P0522R0 support. (Bug report at https://github.com/llvm/llvm-project/issue/63281) Closes #4892
2022-12-15Support adding ByteCount to void/char pointers without castingMaxime Coste
2022-08-20Add support for field width and digit grouping in formatMaxime Coste
2022-05-08Work around incomplete std::to_chars() support in libstdc++ 10Johannes Altmanninger
Ubuntu 20.04 ships GCC's libstdc++ 10 from 2020 which implements std::to_chars() for integers but not for floats. Use the float overload only if the library advertises support via the feature testing macro. This can be removed once we require GCC 11 (see https://www.gnu.org/software/gcc/gcc-11/changes.html). Closes #4607
2022-05-05Use std::to_chars to int to str conversionMaxime Coste
2022-03-06Add a complete-command command to configure command completionMaxime Coste
This makes it possible to change command completion in hooks and paves the way to more flexibility in how custom commands can be completed
2021-11-21Reduce the amount of Regex VM Instruction codeMaxime Coste
Merge all lookarounds into the same instruction, merge splits, merge literal ignore case with literal... Besides reducing the amount of almost duplicated code, this improves performance by reducing pressure on the (often failing) branch target prediction for instruction dispatching by moving branches into the instruction code themselves where they are more likely to be well predicted.
2021-10-23src: Use pre-increment iterator syntaxFrank LENORMAND
Cppcheck produces the following warning: ``` string_utils.cc:24:9: performance: Prefer prefix ++/-- operators for non-primitive types. ``` Fixes #4340
2021-07-31Add a format_with format function that takes a FunctionRef appendMaxime Coste
2020-05-19Output debug memory stats in a nice tableMaxime Coste
2019-11-23Make wrap_lines a lazy range viewMaxime Coste
Avoid the need to allocate a vector by using the ranges framework.
2019-11-09Remove unused trim_whitespaces()Jason Felice
2019-09-17Accept docstrings with last line not fully indentedMaxime Coste
When trimming indent, the last line, if only containing whitespaces does not need to match the indent, so that this indentation style works: -docstring %{ indented string }
2019-07-25src: De-indent docstrings passed to command/option/mapping definitionsFrank LENORMAND
This commit implements formatting behaviour when the first character of a docstring is a newline. In that case, the exact indentation level of the next line will be removed from that line and all subsequent non-empty lines. An error will be returned if a subsequent non-empty line does not have the same indentation level. The docstrings are always trimmed (surrounding whitespaces) whether the first character is a newline or not, as was the case prior to this commit. Example: the following declaration ``` define-command test -docstring %{ test: do something Nothing really. More indented lines. } nop ``` would be rendered as ``` test: do something Nothing really. More indented lines. ``` Related to #2405
2019-07-06Fix build on FreeBSDTobias Kortkamp
file.cc:390:21: error: use of undeclared identifier 'rename'; did you mean 'devname'? if (replace and rename(temp_filename, zfilename) != 0) ^~~~~~ devname /usr/include/stdlib.h:277:7: note: 'devname' declared here char *devname(__dev_t, __mode_t); ^ file.cc:390:28: error: cannot initialize a parameter of type '__dev_t' (aka 'unsigned long') with an lvalue of type 'char [1024]' if (replace and rename(temp_filename, zfilename) != 0) ^~~~~~~~~~~~~ /usr/include/stdlib.h:277:22: note: passing argument to parameter here char *devname(__dev_t, __mode_t); ^ 2 errors generated. --- highlighters.cc:1110:13: error: use of undeclared identifier 'snprintf'; did you mean 'vswprintf'? snprintf(buffer, 16, format, std::abs(line_to_format)); ^~~~~~~~ vswprintf /usr/include/wchar.h:139:5: note: 'vswprintf' declared here int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ highlighters.cc:1110:22: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [16]' snprintf(buffer, 16, format, std::abs(line_to_format)); ^~~~~~ /usr/include/wchar.h:139:35: note: passing argument to parameter here int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ 2 errors generated. --- json_ui.cc:60:13: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? sprintf(buf, "\\u%04x", *next); ^~~~~~~ swprintf /usr/include/wchar.h:133:5: note: 'swprintf' declared here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ json_ui.cc:60:21: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [7]' sprintf(buf, "\\u%04x", *next); ^~~ /usr/include/wchar.h:133:34: note: passing argument to parameter here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ json_ui.cc:74:9: error: use of undeclared identifier 'sprintf' sprintf(buffer, R"("#%02x%02x%02x")", color.r, color.g, color.b); ^ 3 errors generated. --- regex_impl.cc:1039:9: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? sprintf(buf, " %03d ", count++); ^~~~~~~ swprintf /usr/include/wchar.h:133:5: note: 'swprintf' declared here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ regex_impl.cc:1039:17: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [20]' sprintf(buf, " %03d ", count++); ^~~ /usr/include/wchar.h:133:34: note: passing argument to parameter here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ regex_impl.cc:1197:17: error: use of undeclared identifier 'puts' { if (dump) puts(dump_regex(*this).c_str()); } ^ regex_impl.cc:1208:18: note: in instantiation of member function 'Kakoune::(anonymous namespace)::TestVM<Kakoune::RegexMode::Forward>::TestVM' requested here TestVM<> vm{R"(a*b)"}; ^ regex_impl.cc:1197:17: error: use of undeclared identifier 'puts' { if (dump) puts(dump_regex(*this).c_str()); } ^ regex_impl.cc:1283:56: note: in instantiation of member function 'Kakoune::(anonymous namespace)::TestVM<5>::TestVM' requested here TestVM<RegexMode::Forward | RegexMode::Search> vm{R"(f.*a(.*o))"}; ^ regex_impl.cc:1197:17: error: use of undeclared identifier 'puts' { if (dump) puts(dump_regex(*this).c_str()); } ^ regex_impl.cc:1423:57: note: in instantiation of member function 'Kakoune::(anonymous namespace)::TestVM<6>::TestVM' requested here TestVM<RegexMode::Backward | RegexMode::Search> vm{R"(fo{1,})"}; ^ 5 errors generated. --- remote.cc:829:9: error: use of undeclared identifier 'rename'; did you mean 'devname'? if (rename(old_socket_file.c_str(), new_socket_file.c_str()) != 0) ^~~~~~ devname /usr/include/stdlib.h:277:7: note: 'devname' declared here char *devname(__dev_t, __mode_t); ^ remote.cc:829:16: error: cannot initialize a parameter of type '__dev_t' (aka 'unsigned long') with an rvalue of type 'const char *' if (rename(old_socket_file.c_str(), new_socket_file.c_str()) != 0) ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/stdlib.h:277:22: note: passing argument to parameter here char *devname(__dev_t, __mode_t); ^ 2 errors generated. --- string_utils.cc:126:20: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? res.m_length = sprintf(res.m_data, "%i", val); ^~~~~~~ swprintf /usr/include/wchar.h:133:5: note: 'swprintf' declared here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ string_utils.cc:126:28: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [15]' res.m_length = sprintf(res.m_data, "%i", val); ^~~~~~~~~~ /usr/include/wchar.h:133:34: note: passing argument to parameter here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ string_utils.cc:133:20: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? res.m_length = sprintf(res.m_data, "%u", val); ^~~~~~~ swprintf [...]
2018-11-27Make '_' the default extra_word_chars, and remove built-in supportMaxime Coste
Fixes #2599
2018-08-04An empty string is not a valid numberMaxime Coste
Fixes #2284
2018-07-05Introduce a "double_up" function for doubling up escapingMaxime Coste
2018-05-21Fix also the implementation of to_string(size_t) changeMaxime Coste
2018-04-27Add a debug regex command to dump regex instructionsMaxime Coste
2018-04-06Make error messages more consistentDelapouite
2017-12-07Tweak unescape template function to unescape the escape char as wellMaxime Coste
Test that more thouroughly in the unit tests.
2017-12-06Remove Vector returning split functions, use range adaptorMaxime Coste
Do not allocate temporary vectors to store splitted data, use the 'split' range adaptor along with transform(unescape) to provide the same feature with less allocations.
2017-10-10Move all non-core string code to string_utils.{hh,cc}Maxime Coste