abseil-cpp/absl/strings/internal/escaping.h
Go to the documentation of this file.
1 // Copyright 2020 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABSL_STRINGS_INTERNAL_ESCAPING_H_
16 #define ABSL_STRINGS_INTERNAL_ESCAPING_H_
17 
18 #include <cassert>
19 
20 #include "absl/strings/internal/resize_uninitialized.h"
21 
22 namespace absl {
24 namespace strings_internal {
25 
26 ABSL_CONST_INIT extern const char kBase64Chars[];
27 
28 // Calculates how long a string will be when it is base64 encoded given its
29 // length and whether or not the result should be padded.
30 size_t CalculateBase64EscapedLenInternal(size_t input_len, bool do_padding);
31 
32 // Base64-encodes `src` using the alphabet provided in `base64` and writes the
33 // result to `dest`. If `do_padding` is true, `dest` is padded with '=' chars
34 // until its length is a multiple of 3. Returns the length of `dest`.
35 size_t Base64EscapeInternal(const unsigned char* src, size_t szsrc, char* dest,
36  size_t szdest, const char* base64, bool do_padding);
37 
38 // Base64-encodes `src` using the alphabet provided in `base64` and writes the
39 // result to `dest`. If `do_padding` is true, `dest` is padded with '=' chars
40 // until its length is a multiple of 3.
41 template <typename String>
42 void Base64EscapeInternal(const unsigned char* src, size_t szsrc, String* dest,
43  bool do_padding, const char* base64_chars) {
44  const size_t calc_escaped_size =
45  CalculateBase64EscapedLenInternal(szsrc, do_padding);
46  STLStringResizeUninitialized(dest, calc_escaped_size);
47 
48  const size_t escaped_len = Base64EscapeInternal(
49  src, szsrc, &(*dest)[0], dest->size(), base64_chars, do_padding);
50  assert(calc_escaped_size == escaped_len);
51  dest->erase(escaped_len);
52 }
53 
54 } // namespace strings_internal
56 } // namespace absl
57 
58 #endif // ABSL_STRINGS_INTERNAL_ESCAPING_H_
ABSL_CONST_INIT
#define ABSL_CONST_INIT
Definition: abseil-cpp/absl/base/attributes.h:716
absl::strings_internal::kBase64Chars
const ABSL_CONST_INIT char kBase64Chars[]
Definition: abseil-cpp/absl/strings/internal/escaping.cc:24
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::strings_internal::Base64EscapeInternal
size_t Base64EscapeInternal(const unsigned char *src, size_t szsrc, char *dest, size_t szdest, const char *base64, bool do_padding)
Definition: abseil-cpp/absl/strings/internal/escaping.cc:73
tests.qps.qps_worker.dest
dest
Definition: qps_worker.py:45
google::protobuf::compiler::csharp::base64_chars
static const char base64_chars[]
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc:437
absl::strings_internal::STLStringResizeUninitialized
void STLStringResizeUninitialized(string_type *s, size_t new_size)
Definition: abseil-cpp/absl/strings/internal/resize_uninitialized.h:67
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::strings_internal::CalculateBase64EscapedLenInternal
size_t CalculateBase64EscapedLenInternal(size_t input_len, bool do_padding)
Definition: abseil-cpp/absl/strings/internal/escaping.cc:27


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:19