diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1e21d3..efde6e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,8 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${TASKSH_INCLUDE_DIRS}) -set (tasksh_SRCS Color.cpp Color.h) +set (tasksh_SRCS Color.cpp Color.h + text.cpp text.h) add_executable (tasksh_executable main.cpp ${task_SRCS}) diff --git a/src/Color.cpp b/src/Color.cpp index 9a83447..b94c4a1 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/src/eng-USA.h b/src/eng-USA.h new file mode 100644 index 0000000..4c6360c --- /dev/null +++ b/src/eng-USA.h @@ -0,0 +1,113 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// +// This file contains all the strings that should be localized. If a string is +// *not* in this file, then either: +// (a) it should not be localized, or +// (b) you have found a bug - please report it +// +// Strings that should be localized: +// - text output that the user sees +// +// Strings that should NOT be localized: +// - .taskrc configuration variable names +// - command names +// - extension function names +// - certain literals associated with parsing +// - debug strings +// - attribute names +// - modifier names +// - logical operators (and, or, xor) +// +// Rules: +// - Localized strings should not in general contain leading or trailing +// white space, including \n, thus allowing the code to compose strings. +// - Retain the tense of the original string. +// - Retain the same degree of verbosity of the original string. +// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// +// Translators: +// 1. Copy this file (eng-USA.h) to a new file with the target locale as the +// file name. Using German as an example, do this: +// +// cp eng-USA.h deu-DEU.h +// +// 2. Modify all the strings below. +// i.e. change "Unknown error." to "Unbekannter Fehler.". +// +// 3. Add your new translation to the task.git/src/i18n.h file, if necessary, +// by inserting: +// +// #elif PACKAGE_LANGUAGE == LANGUAGE_DEU_DEU +// #include +// +// 4. Add your new language to task.git/CMakeLists.txt, making sure that +// number is unique: +// +// set (LANGUAGE_DEU_DEU 3) +// +// 5. Add your new language to task.git/cmake.h.in: +// +// #define LANGUAGE_DEU_DEU ${LANGUAGE_DEU_DEU} +// +// 6. Build your localized Taskwarrior with these commands: +// +// cd task.git +// cmake -D LANGUAGE=3 . +// make +// +// 7. Submit your translation to support@taskwarrior.org, where it will be +// shared with others. +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_STRINGS +#define INCLUDED_STRINGS + +// Note that for English, the following two lines are not displayed. For all +// other localizations, these lines will appear in the output of the 'version' +// and 'diagnostics' commands. +// +// DO NOT include a copyright in the translation. +// +#define STRING_LOCALIZATION_DESC "English localization" +#define STRING_LOCALIZATION_AUTHOR "Translated into English by A. Person." + + + +// Errors +#define STRING_UNKNOWN_ERROR "Unknown error." + +// Color +#define STRING_COLOR_UNRECOGNIZED "The color '{1}' is not recognized." + +#endif + diff --git a/src/i18n.h b/src/i18n.h new file mode 100644 index 0000000..1c258e3 --- /dev/null +++ b/src/i18n.h @@ -0,0 +1,66 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// +// Strings that should be localized: +// - All text output that the user sees or types +// +// Strings that should NOT be localized: +// - ./taskrc configuration variable names +// - certain literals associated with parsing +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_I18N +#define INCLUDED_I18N + +#include + +// Translators: +// Add more, as appropriate. +#if PACKAGE_LANGUAGE == LANGUAGE_ENG_USA +#include +#endif + +#define CCOLOR_BOLD 500 +#define CCOLOR_UNDERLINE 501 +#define CCOLOR_ON 502 +#define CCOLOR_BRIGHT 503 +#define CCOLOR_BLACK 504 +#define CCOLOR_RED 505 +#define CCOLOR_GREEN 506 +#define CCOLOR_YELLOW 507 +#define CCOLOR_BLUE 508 +#define CCOLOR_MAGENTA 509 +#define CCOLOR_CYAN 510 +#define CCOLOR_WHITE 511 + +#define CCOLOR_OFF 520 +#define CCOLOR_UNKNOWN 521 + +#endif + diff --git a/src/main.cpp b/src/main.cpp index 23b5dd2..3675acf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////////////////////////// int main (int argc, const char** argv) diff --git a/src/text.cpp b/src/text.cpp new file mode 100644 index 0000000..5f58cd0 --- /dev/null +++ b/src/text.cpp @@ -0,0 +1,105 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +static void replace_positional (std::string&, const std::string&, const std::string&); + +//////////////////////////////////////////////////////////////////////////////// +void split ( + std::vector& results, + const std::string& input, + const char delimiter) +{ + results.clear (); + std::string::size_type start = 0; + std::string::size_type i; + while ((i = input.find (delimiter, start)) != std::string::npos) + { + results.push_back (input.substr (start, i - start)); + start = i + 1; + } + + if (input.length ()) + results.push_back (input.substr (start)); +} + +//////////////////////////////////////////////////////////////////////////////// +std::string trimLeft (const std::string& in, const std::string& t /*= " "*/) +{ + std::string out = in; + return out.erase (0, in.find_first_not_of (t)); +} + +//////////////////////////////////////////////////////////////////////////////// +std::string trimRight (const std::string& in, const std::string& t /*= " "*/) +{ + std::string out = in; + return out.erase (out.find_last_not_of (t) + 1); +} + +//////////////////////////////////////////////////////////////////////////////// +std::string trim (const std::string& in, const std::string& t /*= " "*/) +{ + std::string out = in; + return trimLeft (trimRight (out, t), t); +} + +//////////////////////////////////////////////////////////////////////////////// +std::string lowerCase (const std::string& input) +{ + std::string output = input; + std::transform (output.begin (), output.end (), output.begin (), tolower); + return output; +} + +//////////////////////////////////////////////////////////////////////////////// +static void replace_positional ( + std::string& fmt, + const std::string& from, + const std::string& to) +{ + std::string::size_type pos = 0; + while ((pos = fmt.find (from, pos)) != std::string::npos) + { + fmt.replace (pos, from.length (), to); + pos += to.length (); + } +} + +//////////////////////////////////////////////////////////////////////////////// +const std::string format ( + const std::string& fmt, + const std::string& arg1) +{ + std::string output = fmt; + replace_positional (output, "{1}", arg1); + return output; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/text.h b/src/text.h new file mode 100644 index 0000000..29f11f1 --- /dev/null +++ b/src/text.h @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_TEXT +#define INCLUDED_TEXT + +#include +#include + +std::string trimLeft (const std::string& in, const std::string& t = " "); +std::string trimRight (const std::string& in, const std::string& t = " "); +std::string trim (const std::string& in, const std::string& t = " "); +void split (std::vector&, const std::string&, const char); +std::string lowerCase (const std::string&); +const std::string format (const std::string&, const std::string&); + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/test/.gitignore b/test/.gitignore index 51a5699..0c658db 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,3 @@ run_all +all.log +color.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b6cd653..974b505 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,11 +33,10 @@ add_custom_target (build_tests DEPENDS ${test_SRCS} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test) foreach (src_FILE ${test_SRCS}) - add_executable (${src_FILE} "${src_FILE}.cpp" test.cpp) - target_link_libraries (${src_FILE} tasksh ${TASKSH_LIBRARIES}) + add_executable (${src_FILE} "${src_FILE}.cpp" + ../src/Color.cpp + ../src/text.cpp + test.cpp) + target_link_libraries (${src_FILE} ${TASKSH_LIBRARIES}) endforeach (src_FILE) -#SET(CMAKE_BUILD_TYPE gcov) -#SET(CMAKE_CXX_FLAGS_GCOV "--coverage") -#SET(CMAKE_C_FLAGS_GCOV "--coverage") -#SET(CMAKE_EXE_LINKER_FLAGS_GCOV "--coverage") diff --git a/test/template.t b/test/template.t index e8c1dcc..b3048ee 100755 --- a/test/template.t +++ b/test/template.t @@ -48,7 +48,7 @@ my $ut = basename ($0); # Bug - my $output = qx{../src/tasksh --version 2>&1}; ok ($? == 0, "$ut: version check"); -like ($output, qr/tasksh version/ms, "$ut: tasksh version found"); +like ($output, qr/0.9.0.dev/ms, "$ut: tasksh version found"); # Cleanup. #unlink qw(), $rc;