Browse Source

Update documentation for string::.

tags/v1.1.6
Andrew Belt 5 years ago
parent
commit
ba056f6d6a
2 changed files with 4 additions and 3 deletions
  1. +3
    -2
      include/string.hpp
  2. +1
    -1
      src/string.cpp

+ 3
- 2
include/string.hpp View File

@@ -67,8 +67,7 @@ https://en.wikipedia.org/wiki/Base64
std::string toBase64(const uint8_t* data, size_t dataLen);
std::string toBase64(const std::vector<uint8_t>& data);
/** Converts a Base64-encoded string to a byte array.
`outLen` is set to the length of the byte array.
If non-NULL, caller must delete[] the result.
Throws std::runtime_error if string is invalid.
*/
std::vector<uint8_t> fromBase64(const std::string& str);

@@ -77,6 +76,8 @@ std::vector<uint8_t> fromBase64(const std::string& str);
std::vector<uint8_t> compress(const uint8_t* data, size_t dataLen);
std::vector<uint8_t> compress(const std::vector<uint8_t>& data);
/** Uncompress bytes with zlib.
Before calling this function, set `dataLen` to the capacity of `data`.
After returning, `dataLen` is set to the number of bytes written.
Unfortunately the output buffer cannot be computed from the compressed data, so you may need to hard-code the maximum expected size.
*/
void uncompress(const uint8_t* compressed, size_t compressedLen, uint8_t* data, size_t* dataLen);


+ 1
- 1
src/string.cpp View File

@@ -158,7 +158,7 @@ float fuzzyScore(const std::string& s, const std::string& query) {
std::string toBase64(const uint8_t* data, size_t dataLen) {
static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

size_t numBlocks = size_t((dataLen + 2) / 3);
size_t numBlocks = (dataLen + 2) / 3;
size_t strLen = numBlocks * 4;
std::string str;
str.reserve(strLen);


Loading…
Cancel
Save