commit 0789bb7c9b07c1dbcf0fb937e3f9f96165c86031 Author: Daniel Swanson Date: Tue Jul 27 09:45:23 2021 -0500 string_view for old compilers diff --git a/configure.ac b/configure.ac index 05fce75..96baab2 100644 --- a/configure.ac +++ b/configure.ac @@ -46,7 +46,7 @@ AC_CHECK_LIB(xml2, xmlReaderForFile) # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([stdlib.h string.h unistd.h stddef.h]) +AC_CHECK_HEADERS([stdlib.h string.h unistd.h stddef.h string_view]) AC_CHECK_HEADER([utf8.h], [], [AC_MSG_ERROR([You don't have utfcpp installed.])]) # Checks for typedefs, structures, and compiler characteristics. diff --git a/lttoolbox/string_view.h b/lttoolbox/string_view.h new file mode 100644 index 0000000..f5bf267 --- /dev/null +++ b/lttoolbox/string_view.h @@ -0,0 +1,40 @@ +/* +* Copyright (C) 2021 Apertium +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#pragma once +#ifndef LT_STRING_VIEW_HPP__ +#define LT_STRING_VIEW_HPP__ + +#ifdef HAVE_STRING_VIEW + #include +#else + #include + #include + + namespace std { + using string_view = ::std::experimental::string_view; + template + using basic_string_view = ::std::experimental::basic_string_view; + + inline ::std::string& operator+=(::std::string& str, ::std::string_view sv) { + str.append(sv.begin(), sv.end()); + return str; + } + } +#endif + +#endif diff --git a/lttoolbox/ustring.h b/lttoolbox/ustring.h index 3642cbe..5ffa878 100644 --- a/lttoolbox/ustring.h +++ b/lttoolbox/ustring.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include typedef std::basic_string UString; typedef std::basic_string_view UString_view;