Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/siddiqsoft/string2map
Header only C++17 library to parse a string containing delimited key-value pairs into a map container including the feature to convert from std::string to std::wstring and vice-versa.
https://github.com/siddiqsoft/string2map
cpp http-header-parser key-value map parse string tokenize winhttp
Last synced: about 1 month ago
JSON representation
Header only C++17 library to parse a string containing delimited key-value pairs into a map container including the feature to convert from std::string to std::wstring and vice-versa.
- Host: GitHub
- URL: https://github.com/siddiqsoft/string2map
- Owner: SiddiqSoft
- License: bsd-3-clause
- Created: 2020-11-04T10:13:04.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-20T04:42:08.000Z (about 3 years ago)
- Last Synced: 2024-11-10T08:51:43.084Z (about 2 months ago)
- Topics: cpp, http-header-parser, key-value, map, parse, string, tokenize, winhttp
- Language: C++
- Homepage:
- Size: 101 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# string2map and string2vector
[![CodeQL](https://github.com/SiddiqSoft/string2map/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/SiddiqSoft/string2map/actions/workflows/codeql-analysis.yml)
[![Build Status](https://dev.azure.com/siddiqsoft/siddiqsoft/_apis/build/status/SiddiqSoft.string2map?branchName=main)](https://dev.azure.com/siddiqsoft/siddiqsoft/_build/latest?definitionId=3&branchName=main)
![](https://img.shields.io/nuget/v/SiddiqSoft.string2map)
![](https://img.shields.io/github/v/tag/SiddiqSoft/string2map)
![](https://img.shields.io/azure-devops/tests/siddiqsoft/siddiqsoft/2)
![](https://img.shields.io/azure-devops/coverage/siddiqsoft/siddiqsoft/2)Simple C++17 library to aid in the parsing of HTTP headers into a STL map-type container.
## Objective
Convert the input string with the specified delimiters into a map of key-value pairs with the given input:
- std::[w]string
- Key delimiter (example: `: `, `:`, `=`, `= `)
- Value delimiter (end of the key-value pair element, example: CRLF)
- Destination output type for key/value: `string` or `wstring`.
- Destination container type: `map`, `multimap`, `unordered_map`.## API
```cpp
namespace siddiqsoft::string2map
{
template >
R parse(T& src, const T& keyDelimiter, const T& valueDelimiter, const T& terminalDelimiter= T{}) noexcept(false)
}
```typename | Type | Comment
---------|-----------|--------------
`T` | `string` or `wstring` | Type of the source string
`D` | `string` or `wstring` | Type of the destination string (used in the container)
`R` | `map`, `unordered_map`, `multimap` | Generally type is container```cpp
namespace siddiqsoft::string2vector
{
template
std::vector parse(const T& src, const T& keyDelimiter)
}
```typename | Type | Comment
---------|-----------|--------------
`T` | `string` or `wstring` | Type of the source string## Usage
Get it from [nuget](https://www.nuget.org/packages/string2map/) or you can submodule it.
```cpp
#include
#include#include "siddiqsoft/string2map.hpp"
TEST(parse, Test_string2map)
{
std::string sampleStr{ "Host: duplicate\r\n"
"Host: hostname.com\r\n"
"Content-Type: text\r\n"
"Content-Length: 99\r\n\r\n" };auto kvmap= siddiqsoft::string2map::parse // destination container
>(sampleStr);// We expect only 3 items even though there is a duplicate key in the source string.
// The std::map container ensures unique keys.
EXPECT_EQ(3, kvmap.size());
}TEST(parse, Test_string2vector)
{
std::string sampleStr{ "/a/b/c/d" };auto kv= siddiqsoft::string2vector::parse(sampleStr);
EXPECT_EQ(4, kv.size());
}```
© 2020 Siddiq Software LLC. All rights reserved. Refer to [LICENSE](LICENSE).