Use C++17 std::string_view

Thu, 28 Jun 2018 22:05:49 +0200

author
David Demelier <markand@malikania.fr>
date
Thu, 28 Jun 2018 22:05:49 +0200
changeset 17
0b524d7b7669
parent 16
e591bdf85bc2
child 18
bdc4fde21426

Use C++17 std::string_view

CMakeLists.txt file | annotate | diff | comparison | revisions
INSTALL.md file | annotate | diff | comparison | revisions
README.md file | annotate | diff | comparison | revisions
base64.hpp file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Thu May 24 10:55:47 2018 +0200
+++ b/CMakeLists.txt	Thu Jun 28 22:05:49 2018 +0200
@@ -19,7 +19,7 @@
 cmake_minimum_required(VERSION 3.5)
 project(base64 CXX)
 
-set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED On)
 
 set(BASE64_VERSION_MAJOR "2")
--- a/INSTALL.md	Thu May 24 10:55:47 2018 +0200
+++ b/INSTALL.md	Thu Jun 28 22:05:49 2018 +0200
@@ -4,7 +4,7 @@
 Requirements
 ------------
 
-  - C++14.
+  - C++17.
 
 Installation
 ------------
--- a/README.md	Thu May 24 10:55:47 2018 +0200
+++ b/README.md	Thu Jun 28 22:05:49 2018 +0200
@@ -4,9 +4,4 @@
 Introduction
 ------------
 
-Base64 encoding and decoding easily in C++11.
-
-Documentation
--------------
-
-See the the [API reference](http://markand.bitbucket.org/libbase64).
+Base64 encoding and decoding easily in C++17.
--- a/base64.hpp	Thu May 24 10:55:47 2018 +0200
+++ b/base64.hpp	Thu Jun 28 22:05:49 2018 +0200
@@ -58,6 +58,7 @@
 #include <cctype>
 #include <stdexcept>
 #include <string>
+#include <string_view>
 
 /**
  * \brief main %base64 namespace.
@@ -96,7 +97,7 @@
  */
 inline char lookup(unsigned char value) noexcept
 {
-    static const char* table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+    static std::string_view table("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
 
     assert(value < 64);
 
@@ -213,7 +214,7 @@
  * \param input the input string
  * \return the %base64 formatted string
  */
-inline std::string encode(const std::string& input)
+inline std::string encode(std::string_view input)
 {
     std::string result;
 
@@ -229,7 +230,7 @@
  * \return the original string
  * \throw std::invalid_argument on bad %base64 string
  */
-inline std::string decode(const std::string& input)
+inline std::string decode(std::string_view input)
 {
     std::string result;
 

mercurial