Skip to content

Commit 04370a9

Browse files
committed
[skip ci] Improve Readme guided by markdownlint
1 parent 98a0da3 commit 04370a9

File tree

1 file changed

+35
-40
lines changed

1 file changed

+35
-40
lines changed

README.md

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Language](https://img.shields.io/badge/C%2B%2B-98/11/14/17-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization) [![License](https://img.shields.io/badge/license-BSL-blue.svg)](https://opensource.org/licenses/BSL-1.0) [![Build Status](https://travis-ci.org/martinmoene/string-view-lite.svg?branch=master)](https://travis-ci.org/martinmoene/string-view-lite) [![Build status](https://ci.appveyor.com/api/projects/status/1ha3wnxtam547m8p?svg=true)](https://ci.appveyor.com/project/martinmoene/string-view-lite) [![Version](https://badge.fury.io/gh/martinmoene%2Fstring-view-lite.svg)](https://github.com/martinmoene/string-view-lite/releases) [![download](https://img.shields.io/badge/latest-download-blue.svg)](https://github.com/martinmoene/string-view-lite/blob/master/include/nonstd/string_view.hpp) [![Conan](https://img.shields.io/badge/on-conan-blue.svg)](https://bintray.com/conan/conan-center/string-view-lite%3A_) [![Try it on wandbox](https://img.shields.io/badge/on-wandbox-blue.svg)](https://wandbox.org/permlink/ZfX49QqynfuQikTX) [![Try it on godbolt online](https://img.shields.io/badge/on-godbolt-blue.svg)](https://godbolt.org/z/YtxnAn)
44

55
**Contents**
6+
67
- [Example usage](#example-usage)
78
- [In a nutshell](#in-a-nutshell)
89
- [License](#license)
@@ -16,8 +17,7 @@
1617
- [Appendix](#appendix)
1718

1819

19-
Example usage
20-
-------------
20+
## Example usage
2121

2222
```Cpp
2323
#include "nonstd/string_view.hpp"
@@ -26,7 +26,7 @@ Example usage
2626
using namespace std::literals;
2727
using namespace nonstd::literals;
2828
using namespace nonstd;
29-
29+
3030
void write( string_view sv )
3131
{
3232
std::cout << sv;
@@ -41,30 +41,27 @@ int main()
4141
```
4242

4343
### Compile and run
44-
```
44+
45+
```Text
4546
prompt> g++ -Wall -std=c++14 -I../include/ -o 01-basic.exe 01-basic.cpp && 01-basic.exe
4647
hello, world!
4748
```
4849

49-
In a nutshell
50-
---------------
50+
## In a nutshell
51+
5152
**string-view lite** is a single-file header-only library to provide a non-owning reference to a string. The library provides a [C++17-like string_view](http://en.cppreference.com/w/cpp/string/basic_string_view) for use with C++98 and later. If available, `std::string_view` is used, unless [configured otherwise](#configuration).
5253

5354
**Features and properties of string-view lite** are ease of installation (single header), freedom of dependencies other than the standard library. To mimic C++17-like cooperation with `std::string`, `nonstd::string_view` provides several non-standard conversion functions. These functions may be [omitted via configuration](#configuration).
5455

56+
## License
5557

56-
License
57-
-------
5858
*string-view lite* is distributed under the [Boost Software License](LICENSE.txt).
59-
6059

61-
Dependencies
62-
------------
63-
*string-view lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).
60+
## Dependencies
6461

62+
*string-view lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).
6563

66-
Installation
67-
------------
64+
## Installation
6865

6966
*string-view lite* is a single-file header-only library. Put `string_view.hpp` in the [include](include) folder directly into the project source tree or somewhere reachable from your project.
7067

@@ -83,22 +80,20 @@ Or, if you use the [conan package manager](https://www.conan.io/), follow these
8380

8481
conan install
8582

86-
87-
Synopsis
88-
--------
83+
## Synopsis
8984

9085
**Contents**
9186
[Documentation of `std::string_view`](#stdstring_view)
9287
[C++20 extensions](#c20-extensions)
9388
[Non-standard extensions](#non-standard-extensions)
9489
[Configuration](#configuration)
9590

96-
Documentation of `std::string_view`
97-
-----------------------------------
91+
## Documentation of `std::string_view`
92+
9893
Depending on the compiler and C++-standard used, `nonstd::string_view` behaves less or more like `std::string_view`. To get an idea of the capabilities of `nonstd::string_view` with your configuration, look at the output of the [tests](test/string_view.t.cpp), issuing `string-view-lite.t --pass @`. For `std::string_view`, see its [documentation at cppreference](http://en.cppreference.com/w/cpp/string/basic_string_view).
9994

100-
C++20 extensions
101-
----------------
95+
## C++20 extensions
96+
10297
*string_view-lite* provides the following C++20 *extensions*.
10398

10499
- *[[nodiscard]]* constexpr bool **empty**() const noexcept;
@@ -110,18 +105,20 @@ C++20 extensions
110105
- constexpr bool ***ends_with***( CharT const * s ) const; // (3)
111106

112107
Note: [[nodiscard]], constexpr and noexcept if available.
113-
114-
Non-standard extensions
115-
-----------------------
108+
109+
## Non-standard extensions
110+
116111
### `string_view` literals `sv` and `_sv`
112+
117113
clang compilers do not allow to write `auto sv = "..."sv` with *string-view lite* under C++11. To still provide a literal operator that can be used in that case, *string-view lite* also provides `_sv`. See section [Configuration](#configuration) for how to control the presence of these operators.
118114

119115
The literal operators are declared in the namespace `nonstd::literals::string_view_literals`, where both `literals` and `string_view_literals` are inline namespaces, if supported. Access to these operators can be gained with using namespace `nonstd::literals`, using namespace `nonstd::string_view_literals`, and using namespace `nonstd::literals::string_view_literals`. If inline namespaces are not supported by the compiler, only the latter form is available.
120116

121117
### Cooperation between `std::string` and `nonstd::string_view`
118+
122119
*string-view lite* can provide several methods and free functions to mimic the cooperation between `std::string` and `nonstd::string_view` that exists in C++17. See the table below. Several macros allow you to control the presence of these functions, see section [Configuration](#configuration).
123120

124-
| Kind | Std | Function or method |
121+
| Kind | Std | Function or method |
125122
|-----------------------|-------|--------------------|
126123
| **Free functions** |&nbsp; | macro `nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS`|
127124
| **`std::string_view`**|&nbsp; | &nbsp; |
@@ -153,16 +150,15 @@ The literal operators are declared in the namespace `nonstd::literals::string_vi
153150
| &nbsp; |&nbsp; | constexpr u32string_view operator "" **_sv**( const char32_t* str, size_t len ) noexcept; |
154151
| &nbsp; |&nbsp; | constexpr wstring_view operator "" **_sv**( const wchar_t* str, size_t len ) noexcept; |
155152

156-
157-
Configuration
158-
-------------
153+
## Configuration
159154

160155
### Standard selection macro
161156

162157
\-D<b>nssv\_CPLUSPLUS</b>=199711L
163158
Define this macro to override the auto-detection of the supported C++ standard, if your compiler does not set the `__cpluplus` macro correctly.
164159

165160
### Select `std::string_view` or `nonstd::string_view`
161+
166162
At default, *string-view lite* uses `std::string_view` if it is available and lets you use it via namespace `nonstd`. You can however override this default and explicitly request to use `std::string_view` as `nonstd::string_view` or use string-view lite's `nonstd::string_view` via the following macros.
167163

168164
-D<b>nssv\_CONFIG\_SELECT\_STRING_VIEW</b>=nssv_STRING_VIEW_DEFAULT
@@ -171,6 +167,7 @@ Define this to `nssv_STRING_VIEW_STD` to select `std::string_view` as `nonstd::s
171167
Note: <b>nssv_CONFIG_SELECT_STD_STRING_VIEW</b> and <b>nssv_CONFIG_SELECT_NONSTD_STRING_VIEW</b> are deprecated and have been removed.
172168

173169
### Disable exceptions
170+
174171
-D<b>nssv\_CONFIG\_NO\_EXCEPTIONS</b>=0
175172
Define this to 1 if you want to compile without exceptions. If not defined, the header tries and detect if exceptions have been disabled (e.g. via `-fno-exceptions`). Default is undefined.
176173

@@ -183,6 +180,7 @@ Define this to 1 to provide literal operator `sv` to create a `string_view` from
183180
Define this to 0 to omit literal operator `_sv` to create a `string_view` from a literal string. Default is 1.
184181

185182
### Omit cooperation between `std::string`&ndash;`nonstd::string_view`
183+
186184
At default, *string-view lite* provides several methods and free functions to mimic the cooperation between `std::string` and `nonstd::string_view` (or `std::string_view`) that exists in C++17. See section [Non-standard extensions](#non-standard-extensions). The following macros allow you to control the presence of these functions.
187185

188186
-D<b>nssv_CONFIG_CONVERSION_STD_STRING</b>=1
@@ -194,9 +192,8 @@ Define this to 1 to provide `std::string`&ndash; `nonstd::string_view` interoper
194192
-D<b>nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS</b>=1
195193
Define this to 1 to provide `std::string`&ndash; `nonstd::string_view` interoperability via free functions, define it to 0 to omit all said functions. This also controls the presence of these function if `std::string_view` is used. Default is undefined.
196194

195+
## Reported to work with
197196

198-
Reported to work with
199-
---------------------
200197
The table below mentions the compiler versions *string-view lite* is reported to work with.
201198

202199
OS | Compiler | Versions |
@@ -208,9 +205,8 @@ GNU/Linux | Clang/LLVM | 3.5 - 6.0 |
208205
&nbsp; | GCC | 4.8 - 8 |
209206
OS X | Clang/LLVM | Xcode 6, Xcode 7, Xcode 8, Xcode 9 |
210207

208+
## Building the tests
211209

212-
Building the tests
213-
------------------
214210
To build the tests you need:
215211

216212
- [CMake](http://cmake.org), version 3.0 or later to be installed and in your PATH.
@@ -241,28 +237,29 @@ Here we use c:\string-view-lite\build-win-x86-vc10.
241237

242238
All tests should pass, indicating your platform is supported and you are ready to use *string-view lite*.
243239

240+
## Other implementations of string_view
244241

245-
Other implementations of string_view
246-
------------------------------------
247242
- Marshall Clow. [string_view implementation for libc++](https://github.com/mclow/string_view). GitHub.
248243
- LLVM libc++. [string_view](https://llvm.org/svn/llvm-project/libcxx/trunk/include/string_view). GitHub.
249244
- Matthew Rodusek's, @bitwizeshift. [string_view Standalone](https://github.com/bitwizeshift/string_view-standalone). GitHub.
250245
- @satoren. [string_view for C++03 C++11 C++14](https://github.com/satoren/string_view). GitHub.
251246
- Google Abseil [string_view](https://github.com/abseil/abseil-cpp/tree/master/absl/strings) (non-templated).
252247
- [Search _string view c++_ on GitHub](https://github.com/search?l=C%2B%2B&q=string+view+c%2B%2B&type=Repositories&utf8=%E2%9C%93).
253248

249+
## Notes and references
254250

255-
Notes and references
256-
--------------------
257251
*Interface and specification*
252+
258253
- [string_view on cppreference](http://en.cppreference.com/w/cpp/string/basic_string_view).
259254
- [n4659 - C++17 Working Draft: string_view](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf#page=780).
260255

261256
*Presentations*
257+
262258
- Marshall Clow. [string_view - when to use it, and when not](https://cppcon2015.sched.com/event/3vch/stringview-when-to-use-it-and-when-not?iframe=yes&w=700&sidebar=yes&bg=no#). CppCon 2015. [video](https://youtu.be/H9gAaNRoon4), [slides](https://github.com/CppCon/CppCon2015/blob/master/Presentations/string_view/string_view%20-%20Marshall%20Clow%20-%20CppCon%202015.pdf).
263259
- Neil MacIntosh. [A few good types: Evolving array_view and string_view for safe C++ code](https://cppcon2015.sched.com/event/3vbQ/a-few-good-types-evolving-arrayview-and-stringview-for-safe-c-code). CppCon 2015. [video](https://youtu.be/C4Z3c4Sv52U), [slides](https://github.com/CppCon/CppCon2015/blob/master/Presentations/A%20Few%20Good%20Types/A%20Few%20Good%20Types%20-%20Neil%20MacIntosh%20-%20CppCon%202015.pdf).
264260

265261
*Proposals*
262+
266263
- Jeffrey Yasskin. [n3334 - Proposing array_ref<T> and string_ref](https://wg21.link/n3334). 2012.
267264
- Jeffrey Yasskin. [n3921 - string_view: a non-owning reference to a string, revision 7](http://wg21.link/n3921). **Adopted 2014-02**.
268265
- Alisdair Meredith. [n4288 - Strike string_view::clear from Library Fundamentals](http://wg21.link/n4288). **Adopted 2014-11**.
@@ -274,17 +271,15 @@ Notes and references
274271
- Peter Sommerlad. [p0506 - use string_view for library function parameters instead of const string &/const char *](http://wg21.link/p0506). 2017.
275272
- Daniel Krugler. [wg2946 - LWG 2758's resolution missed further corrections](https://wg21.link/lwg2946). 2017.
276273

277-
278-
Appendix
279-
--------
274+
## Appendix
280275

281276
### A.1 Compile-time information
282277

283278
The version of *string-view lite* is available via tag `[.version]`. The following tags are available for information on the compiler and on the C++ standard library used: `[.compiler]`, `[.stdc++]`, `[.stdlanguage]` and `[.stdlibrary]`.
284279

285280
### A.2 string-view lite test specification
286281

287-
```
282+
```Text
288283
string_view: Allows to default construct an empty string_view
289284
string_view: Allows to construct from pointer and size
290285
string_view: Allows to construct from C-string

0 commit comments

Comments
 (0)