aboutsummaryrefslogtreecommitdiff
path: root/hello.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hello.cpp')
-rw-r--r--hello.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/hello.cpp b/hello.cpp
new file mode 100644
index 0000000..c56dd7b
--- /dev/null
+++ b/hello.cpp
@@ -0,0 +1,40 @@
+#include <iostream>
+#include <string>
+#include <regex>
+
+static std::string get_next_filename(std::string filename)
+{
+ std::regex
+ numbered_reg("(.[^.]*)[(]([1-9][0-9]{0,8})[)](([.].*)?)"),
+ unnumbered_reg("(.[^.]*)(([.].*)?)");
+ std::smatch what;
+ std::string base_name, number, rest;
+ long new_idx;
+
+ if (regex_match(filename, what, numbered_reg)) {
+ base_name = what[1];
+ number = what[2];
+ rest = what[3];
+ new_idx = std::stol(number) + 1;
+ } else {
+ regex_match(filename, what, unnumbered_reg);
+ base_name = what[1];
+ rest = what[2];
+ new_idx = 1;
+ }
+ std:: cout << filename << " ";
+ return base_name + "(" + std::to_string(new_idx) + ")" + rest;
+}
+
+int main()
+{
+ std::cout << get_next_filename("dupa(1)") << std::endl;
+ std::cout << get_next_filename("dupa(1).txt") << std::endl;
+ std::cout << get_next_filename("....dupa(1).txt") << std::endl;
+ std::cout << get_next_filename("dupa(01).kupa(22).png") << std::endl;
+ std::cout << get_next_filename("dupa(1)e..txt") << std::endl;
+ std::cout << get_next_filename("dupa(111111111).txt") << std::endl;
+ std::cout << get_next_filename("dupa(1111111111).txt") << std::endl;
+ std::cout << get_next_filename("dupa.txt") << std::endl;
+ return 0;
+}