1 //
2 // Copyright 2017 The Abseil Authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      https://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #include "absl/strings/internal/str_format/extension.h"
17 
18 #include <errno.h>
19 #include <algorithm>
20 #include <string>
21 
22 namespace absl {
23 ABSL_NAMESPACE_BEGIN
24 namespace str_format_internal {
25 
ToString() const26 std::string Flags::ToString() const {
27   std::string s;
28   s.append(left     ? "-" : "");
29   s.append(show_pos ? "+" : "");
30   s.append(sign_col ? " " : "");
31   s.append(alt      ? "#" : "");
32   s.append(zero     ? "0" : "");
33   return s;
34 }
35 
PutPaddedString(string_view v,int w,int p,bool l)36 bool FormatSinkImpl::PutPaddedString(string_view v, int w, int p, bool l) {
37   size_t space_remaining = 0;
38   if (w >= 0) space_remaining = w;
39   size_t n = v.size();
40   if (p >= 0) n = std::min(n, static_cast<size_t>(p));
41   string_view shown(v.data(), n);
42   space_remaining = Excess(shown.size(), space_remaining);
43   if (!l) Append(space_remaining, ' ');
44   Append(shown);
45   if (l) Append(space_remaining, ' ');
46   return true;
47 }
48 
49 }  // namespace str_format_internal
50 ABSL_NAMESPACE_END
51 }  // namespace absl
52