Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "absl/strings/internal/str_format/extension.h"
00017
00018 #include <errno.h>
00019 #include <algorithm>
00020 #include <string>
00021
00022 namespace absl {
00023 namespace str_format_internal {
00024 namespace {
00025
00026 #define ABSL_LENGTH_MODS_EXPAND_ \
00027 X_VAL(h) X_SEP \
00028 X_VAL(hh) X_SEP \
00029 X_VAL(l) X_SEP \
00030 X_VAL(ll) X_SEP \
00031 X_VAL(L) X_SEP \
00032 X_VAL(j) X_SEP \
00033 X_VAL(z) X_SEP \
00034 X_VAL(t) X_SEP \
00035 X_VAL(q)
00036
00037 }
00038
00039 const LengthMod::Spec LengthMod::kSpecs[] = {
00040 #define X_VAL(id) { LengthMod::id, #id, strlen(#id) }
00041 #define X_SEP ,
00042 ABSL_LENGTH_MODS_EXPAND_, {LengthMod::none, "", 0}
00043 #undef X_VAL
00044 #undef X_SEP
00045 };
00046
00047 const ConversionChar::Spec ConversionChar::kSpecs[] = {
00048 #define X_VAL(id) { ConversionChar::id, #id[0] }
00049 #define X_SEP ,
00050 ABSL_CONVERSION_CHARS_EXPAND_(X_VAL, X_SEP),
00051 {ConversionChar::none, '\0'},
00052 #undef X_VAL
00053 #undef X_SEP
00054 };
00055
00056 std::string Flags::ToString() const {
00057 std::string s;
00058 s.append(left ? "-" : "");
00059 s.append(show_pos ? "+" : "");
00060 s.append(sign_col ? " " : "");
00061 s.append(alt ? "#" : "");
00062 s.append(zero ? "0" : "");
00063 return s;
00064 }
00065
00066 const size_t LengthMod::kNumValues;
00067
00068 const size_t ConversionChar::kNumValues;
00069
00070 bool FormatSinkImpl::PutPaddedString(string_view v, int w, int p, bool l) {
00071 size_t space_remaining = 0;
00072 if (w >= 0) space_remaining = w;
00073 size_t n = v.size();
00074 if (p >= 0) n = std::min(n, static_cast<size_t>(p));
00075 string_view shown(v.data(), n);
00076 space_remaining = Excess(shown.size(), space_remaining);
00077 if (!l) Append(space_remaining, ' ');
00078 Append(shown);
00079 if (l) Append(space_remaining, ' ');
00080 return true;
00081 }
00082
00083 }
00084 }