Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
<!-- markdownlint-disable-next-line line-length -->
![Library Status](https://raw.githubusercontent.com/bemanproject/beman/refs/heads/main/images/badges/beman_badge-beman_library_under_development.svg) ![Continuous Integration Tests](https://github.com/dascandy/cstring_view/actions/workflows/ci_tests.yml/badge.svg) ![Lint Check (pre-commit)](https://github.com/dascandy/cstring_view/actions/workflows/pre-commit.yml/badge.svg)

`beman.cstring_view` is a header-only `cstring_view` library.
`beman.cstring_view` is a header-only `cstring_view` library.

**Implements**: `std::cstring_view` proposed in [cstring\_view (P3655R2)](https://wg21.link/P3655R2).

**Status**: [Under development and not yet ready for production use.](https://github.com/bemanproject/beman/blob/main/docs/beman_library_maturity_model.md#under-development-and-not-yet-ready-for-production-use)

## Usage

`std::cstring_view` exposes a string\_view like type that is intended for being able to propagate prior knowledge that a string is null-terminated throughout the type system, while fulfilling the same role as string\_view.
`std::cstring_view` exposes a string\_view like type that is intended for being able to propagate prior knowledge that
a string is null-terminated throughout the type system, while fulfilling the same role as string\_view.

### Usage: default projection in constrained algorithms

Expand All @@ -27,8 +28,7 @@ The following code snippet illustrates how we can use `cstring_view` to make a b

int main(int argc, const char** argv) {
std::vector<cstring_view> args(argv, argv+argc);

}
}
```

Full runnable examples can be found in [`examples/`](examples/).
Expand Down
18 changes: 9 additions & 9 deletions docs/using_cstring_view.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# Using cstring_view
# Using `cstring_view`

The cstring_view proposal creates a new type that is a null-terminated string view. To use the library in your code, add the project in your cmakefiles:
The `cstring_view` proposal creates a new type that is a null-terminated string view. To use the library in your code,
add the project in your cmakefiles:

```cmake
add_subdirectory(beman/cstring_view)
```

and add the beman::cstring_view project to your target
and add the `beman::cstring_view` project to your target

```cmake
target_link_libraries(my_project PRIVATE beman/cstring_view)
```

Subsequently include the cstring_view header in your code
Subsequently include the `cstring_view` header in your code

```cpp
#include <beman/cstring_view/cstring_view.hpp>
```

From this point on, you're able to use the cstring_view type to handle cases where you have NUL-terminated strings.
From this point on, you're able to use the `cstring_view` type to handle cases where you have NUL-terminated strings.

# Simple examples
## Simple examples

Creating a `cstring_view` can be done from a `std::string`, from a string literal, or from a pointer or buffer that is known to contain a NUL-terminated string. For example:
Creating a `cstring_view` can be done from a `std::string`, from a string literal, or from a pointer or buffer that is
known to contain a NUL-terminated string. For example:

```cpp
cstring_view v = "Hello World!";
Expand All @@ -35,5 +37,3 @@ Such a `cstring_view` can be used in places where a NUL-terminated string is exp
```cpp
puts(v.c_str());
```


5 changes: 4 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ message("Examples to be built: ${ALL_EXAMPLES}")

foreach(example ${ALL_EXAMPLES})
add_executable(beman.cstring_view.examples.${example})
target_sources(beman.cstring_view.examples.${example} PRIVATE ${example}.cpp)
target_sources(
beman.cstring_view.examples.${example}
PRIVATE ${example}.cpp
)
target_link_libraries(
beman.cstring_view.examples.${example}
PRIVATE beman::cstring_view
Expand Down
8 changes: 4 additions & 4 deletions examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::string_view to_string(std::strong_ordering order) {
}

int main() {
std::string s = "hello world";
std::string s = "hello world";
beman::cstring_view z0 = "hello";
beman::cstring_view z1 = s;
beman::cstring_view empty;
Expand All @@ -44,8 +44,8 @@ int main() {
std::cout << z0.c_str() << "\n";
std::cout << "\"" << empty << "\"\n";
std::cout << (empty == ""_csv) << "\n";
std::wstring ws = L"hello world";

std::wstring ws = L"hello world";
beman::wcstring_view wz0 = L"hello";
beman::wcstring_view wz1 = ws;
beman::wcstring_view wempty;
Expand All @@ -55,7 +55,7 @@ int main() {
std::cout << wz0.starts_with(L"hello") << "\n";
std::cout << wz0.starts_with(L"hello"_csv) << "\n";
std::cout << std::hash<beman::wcstring_view>{}(wz1) << "\n";
std::wcout<<wz1<<std::endl;
std::wcout << wz1 << std::endl;
std::cout << (L"hello"_csv == L"hello"sv) << "\n";
std::cout << (L"hello"_csv == L"hello"_csv) << "\n";
std::cout << (L"hello"_csv != L"goodbye"sv) << "\n";
Expand Down
Loading
Loading