|
| 1 | +//===-- Format specifier converter implmentation for strftime -------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See htto_conv.times://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "src/__support/macros/config.h" |
| 10 | +#include "src/stdio/printf_core/writer.h" |
| 11 | +#include "src/time/strftime_core/core_structs.h" |
| 12 | + |
| 13 | +// #include "composite_converter.h" |
| 14 | +#include "num_converter.h" |
| 15 | +// #include "str_converter.h" |
| 16 | + |
| 17 | +namespace LIBC_NAMESPACE_DECL { |
| 18 | +namespace strftime_core { |
| 19 | + |
| 20 | +int convert(printf_core::Writer *writer, const FormatSection &to_conv, |
| 21 | + const tm *timeptr) { |
| 22 | + // TODO: Implement the locale support. |
| 23 | + if (to_conv.modifier != ConvModifier::none) { |
| 24 | + return writer->write(to_conv.raw_string); |
| 25 | + } |
| 26 | + |
| 27 | + if (!to_conv.has_conv) |
| 28 | + return writer->write(to_conv.raw_string); |
| 29 | + switch (to_conv.conv_name) { |
| 30 | + // The cases are grouped by type, then alphabetized with lowercase before |
| 31 | + // uppercase. |
| 32 | + |
| 33 | + // raw conversions |
| 34 | + case '%': |
| 35 | + return writer->write("%"); |
| 36 | + case 'n': |
| 37 | + return writer->write("\n"); |
| 38 | + case 't': |
| 39 | + return writer->write("\t"); |
| 40 | + |
| 41 | + // numeric conversions |
| 42 | + case 'C': // Century |
| 43 | + case 'd': // Day of the month [01-31] |
| 44 | + case 'e': // Day of the month [1-31] |
| 45 | + case 'g': // last 2 digits of ISO year |
| 46 | + case 'G': // ISO year |
| 47 | + case 'H': // 24-hour format |
| 48 | + case 'I': // 12-hour format |
| 49 | + case 'j': // Day of the year |
| 50 | + case 'm': // Month of the year |
| 51 | + case 'M': // Minute of the hour |
| 52 | + case 's': // Seconds since the epoch |
| 53 | + case 'S': // Second of the minute |
| 54 | + case 'u': // ISO day of the week ([1-7] starting Monday) |
| 55 | + case 'U': // Week of the year ([00-53] week 1 starts on first *Sunday*) |
| 56 | + case 'V': // ISO week number ([01-53], 01 is first week majority in this year) |
| 57 | + case 'w': // Day of week ([0-6] starting Sunday) |
| 58 | + case 'W': // Week of the year ([00-53] week 1 starts on first *Monday*) |
| 59 | + case 'y': // Year of the Century |
| 60 | + case 'Y': // Full year |
| 61 | + return convert_int(writer, to_conv, timeptr); |
| 62 | + |
| 63 | + // string conversions |
| 64 | + case 'a': // Abbreviated weekday name |
| 65 | + case 'A': // Full weekday name |
| 66 | + case 'b': // Abbreviated month name |
| 67 | + case 'B': // Full month name |
| 68 | + case 'h': // same as %b |
| 69 | + case 'p': // AM/PM designation |
| 70 | + case 'z': // Timezone offset (+/-hhmm) |
| 71 | + case 'Z': // Timezone name |
| 72 | + // return write_str(writer, to_conv, timeptr); |
| 73 | + |
| 74 | + // composite conversions |
| 75 | + case 'c': // locale specified date and time |
| 76 | + case 'D': // %m/%d/%y (month/day/year) |
| 77 | + case 'F': // %Y-%m-%d (year-month-day) |
| 78 | + case 'r': // %I:%M:%S %p (hour:minute:second AM/PM) |
| 79 | + case 'R': // %H:%M (hour:minute) |
| 80 | + case 'T': // %H:%M:%S (hour:minute:second) |
| 81 | + case 'x': // locale specified date |
| 82 | + case 'X': // locale specified time |
| 83 | + // return write_composite(writer, to_conv, timeptr); |
| 84 | + default: |
| 85 | + return writer->write(to_conv.raw_string); |
| 86 | + } |
| 87 | + return 0; |
| 88 | +} |
| 89 | + |
| 90 | +} // namespace strftime_core |
| 91 | +} // namespace LIBC_NAMESPACE_DECL |
0 commit comments