Add syntax highlighting to README. Fix capitalisation in README

This commit is contained in:
nabijaczleweli 2018-02-25 07:12:32 +01:00
parent 35cd39a622
commit 332cb416e4
No known key found for this signature in database
GPG Key ID: BCFD0B018D2658F1

View File

@ -21,7 +21,7 @@ Generators:
| Name | Description | | Name | Description |
| ---- | ----------- | | ---- | ----------- |
| `uuid_system_generator` | a function object that generates new UUIDs using operating system resources (`CoCreateGuid` on Windows, `uuid_generate` on Linux, `CFUUIDCreate` on Mac) | | `uuid_system_generator` | a function object that generates new UUIDs using operating system resources (`CoCreateGuid` on Windows, `uuid_generate` on Linux, `CFUUIDCreate` on Mac) |
| ` basic_uuid_random_generator` | a function object that generates version 4 UUIDs using a pseudo-random number generator engine. | | `basic_uuid_random_generator` | a function object that generates version 4 UUIDs using a pseudo-random number generator engine. |
| `uuid_random_generator` | a basic_uuid_random_generator using the Marsenne Twister engine, i.e. `basic_uuid_random_generator<std::mt19937>` | | `uuid_random_generator` | a basic_uuid_random_generator using the Marsenne Twister engine, i.e. `basic_uuid_random_generator<std::mt19937>` |
| `uuid_name_generator` | a function object that generates version 5, name-based UUIDs using SHA1 hashing. | | `uuid_name_generator` | a function object that generates version 5, name-based UUIDs using SHA1 hashing. |
@ -47,13 +47,13 @@ This project is currently under development and should be ignored until further
## Using the library ## Using the library
The following is a list of examples for using the library: The following is a list of examples for using the library:
* Creating a nil UUID * Creating a nil UUID
``` ```cpp
uuid empty; uuid empty;
assert(empty.nil()); assert(empty.nil());
assert(empty.size() == 16); assert(empty.size() == 16);
``` ```
* Creating a new UUID * Creating a new UUID
``` ```cpp
uuid const guid = uuids::uuid_system_generator{}(); uuid const guid = uuids::uuid_system_generator{}();
assert(!guid.nil()); assert(!guid.nil());
assert(guid.size() == 16); assert(guid.size() == 16);
@ -61,7 +61,7 @@ assert(guid.version() == uuids::uuid_version::random_number_based);
assert(guid.variant() == uuids::uuid_variant::rfc); assert(guid.variant() == uuids::uuid_variant::rfc);
``` ```
* Creating a new UUID with a default random generator * Creating a new UUID with a default random generator
``` ```cpp
uuids::uuid_random_generator gen; uuids::uuid_random_generator gen;
uuid const guid = gen(); uuid const guid = gen();
assert(!guid.nil()); assert(!guid.nil());
@ -70,7 +70,7 @@ assert(guid.version() == uuids::uuid_version::random_number_based);
assert(guid.variant() == uuids::uuid_variant::rfc); assert(guid.variant() == uuids::uuid_variant::rfc);
``` ```
* Creating a new UUID with a particular random generator * Creating a new UUID with a particular random generator
``` ```cpp
std::random_device rd; std::random_device rd;
std::ranlux48_base generator(rd()); std::ranlux48_base generator(rd());
uuids::basic_uuid_random_generator<std::ranlux48_base> gen(&generator); uuids::basic_uuid_random_generator<std::ranlux48_base> gen(&generator);
@ -82,7 +82,7 @@ assert(guid.version() == uuids::uuid_version::random_number_based);
assert(guid.variant() == uuids::uuid_variant::rfc); assert(guid.variant() == uuids::uuid_variant::rfc);
``` ```
* Creating a new UUID with the name generator * Creating a new UUID with the name generator
``` ```cpp
uuids::uuid_name_generator gen; uuids::uuid_name_generator gen;
uuid const guid = gen(); uuid const guid = gen();
assert(!guid.nil()); assert(!guid.nil());
@ -91,7 +91,7 @@ assert(guid.version() == uuids::uuid_version::name_based_sha1);
assert(guid.variant() == uuids::uuid_variant::rfc); assert(guid.variant() == uuids::uuid_variant::rfc);
``` ```
* Create a UUID from a string * Create a UUID from a string
``` ```cpp
using namespace std::string_literals; using namespace std::string_literals;
auto str = "47183823-2574-4bfd-b411-99ed177d3e43"s; auto str = "47183823-2574-4bfd-b411-99ed177d3e43"s;
@ -99,13 +99,13 @@ uuid guid(str);
assert(guid.string() == str); assert(guid.string() == str);
``` ```
or or
``` ```cpp
auto str = L"47183823-2574-4bfd-b411-99ed177d3e43"s; auto str = L"47183823-2574-4bfd-b411-99ed177d3e43"s;
uuid guid(str); uuid guid(str);
assert(guid.wstring() == str); assert(guid.wstring() == str);
``` ```
* Creating a UUID from an array * Creating a UUID from an array
``` ```cpp
std::array<uuids::uuid::value_type, 16> arr{{ std::array<uuids::uuid::value_type, 16> arr{{
0x47, 0x18, 0x38, 0x23, 0x47, 0x18, 0x38, 0x23,
0x25, 0x74, 0x25, 0x74,
@ -116,7 +116,7 @@ uuid guid(std::begin(arr), std::end(arr));
assert(id.string() == "47183823-2574-4bfd-b411-99ed177d3e43"); assert(id.string() == "47183823-2574-4bfd-b411-99ed177d3e43");
``` ```
or or
``` ```cpp
uuids::uuid::value_type arr[16] = { uuids::uuid::value_type arr[16] = {
0x47, 0x18, 0x38, 0x23, 0x47, 0x18, 0x38, 0x23,
0x25, 0x74, 0x25, 0x74,
@ -126,8 +126,8 @@ uuids::uuid::value_type arr[16] = {
uuid guid(std::begin(arr), std::end(arr)); uuid guid(std::begin(arr), std::end(arr));
assert(guid.string() == "47183823-2574-4bfd-b411-99ed177d3e43"); assert(guid.string() == "47183823-2574-4bfd-b411-99ed177d3e43");
``` ```
* Comparing UUIDS * Comparing UUIDs
``` ```cpp
uuid empty; uuid empty;
uuid guid = uuids::uuid_system_generator{}(); uuid guid = uuids::uuid_system_generator{}();
@ -135,8 +135,8 @@ assert(empty == empty);
assert(guid == guid); assert(guid == guid);
assert(empty != guid); assert(empty != guid);
``` ```
* Swapping UUIDS * Swapping UUIDs
``` ```cpp
uuid empty; uuid empty;
uuid guid = uuids::uuid_system_generator{}(); uuid guid = uuids::uuid_system_generator{}();
@ -154,13 +154,13 @@ assert(empty.nil());
assert(!guid.nil()); assert(!guid.nil());
``` ```
* Converting to string * Converting to string
``` ```cpp
uuid empty; uuid empty;
assert(uuids::to_string(empty) == "00000000-0000-0000-0000-000000000000"); assert(uuids::to_string(empty) == "00000000-0000-0000-0000-000000000000");
assert(uuids::to_wstring(empty) == L"00000000-0000-0000-0000-000000000000"); assert(uuids::to_wstring(empty) == L"00000000-0000-0000-0000-000000000000");
``` ```
* Iterating through the UUID data * Iterating through the UUID data
``` ```cpp
std::array<uuids::uuid::value_type, 16> arr{{ std::array<uuids::uuid::value_type, 16> arr{{
0x47, 0x18, 0x38, 0x23, 0x47, 0x18, 0x38, 0x23,
0x25, 0x74, 0x25, 0x74,
@ -180,7 +180,7 @@ for (auto const & b : guid)
assert(arr[i++] == b); assert(arr[i++] == b);
``` ```
* Using with an orderered associative container * Using with an orderered associative container
``` ```cpp
uuids::uuid_random_generator gen; uuids::uuid_random_generator gen;
std::set<uuids::uuid> ids{uuid{}, gen(), gen(), gen(), gen()}; std::set<uuids::uuid> ids{uuid{}, gen(), gen(), gen(), gen()};
@ -188,7 +188,7 @@ assert(ids.size() == 5);
assert(ids.find(uuid{}) != ids.end()); assert(ids.find(uuid{}) != ids.end());
``` ```
* Using in an unordered associative container * Using in an unordered associative container
``` ```cpp
uuids::uuid_random_generator gen; uuids::uuid_random_generator gen;
std::unordered_set<uuids::uuid> ids{uuid{}, gen(), gen(), gen(), gen()}; std::unordered_set<uuids::uuid> ids{uuid{}, gen(), gen(), gen(), gen()};
@ -196,7 +196,7 @@ assert(ids.size() == 5);
assert(ids.find(uuid{}) != ids.end()); assert(ids.find(uuid{}) != ids.end());
``` ```
* Hashing UUIDs * Hashing UUIDs
``` ```cpp
auto h1 = std::hash<std::string>{}; auto h1 = std::hash<std::string>{};
auto h2 = std::hash<uuid>{}; auto h2 = std::hash<uuid>{};
assert(h1(str) == h2(guid)); assert(h1(str) == h2(guid));