this repo has no description
1/* Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) */
2#pragma once
3
4#include "handles.h"
5#include "objects.h"
6#include "thread.h"
7
8namespace py {
9
10struct FormatSpec {
11 char alignment;
12 char positive_sign;
13 char thousands_separator;
14 bool alternate;
15 int32_t fill_char;
16 int32_t type;
17 word width;
18 word precision;
19};
20
21// Format float as a decimal number with `format` spec. Returns a `str`.
22RawObject formatFloat(Thread* thread, double value, FormatSpec* format);
23
24// Format int as decimal number with `format` spec. Returns a `str`.
25RawObject formatIntDecimal(Thread* thread, const Int& value,
26 FormatSpec* format);
27
28// Format int as decimal number. Returns a `str`.
29RawObject formatIntDecimalSimple(Thread* thread, const Int& value);
30
31// Format int as binary number with `format` spec. Returns a `str`.
32RawObject formatIntBinary(Thread* thread, const Int& value, FormatSpec* format);
33
34// Format int as binary number with `0b` prefix. Returns a `str`.
35RawObject formatIntBinarySimple(Thread* thread, const Int& value);
36
37// Format int as lower cased hexadecimal number with `format` spec.
38// Returns a `str`.
39RawObject formatIntHexadecimalLowerCase(Thread* thread, const Int& value,
40 FormatSpec* format);
41
42// Format int as upper cased hexadecimal number with `format` spec.
43// Returns a `str`.
44RawObject formatIntHexadecimalUpperCase(Thread* thread, const Int& value,
45 FormatSpec* format);
46
47// Format int as lower cased hexadecimal number with `0x` prefix.
48// Returns a `str`.
49RawObject formatIntHexadecimalSimple(Thread* thread, const Int& value);
50
51// Format int as octal number with `format` spec. Returns a `str`.
52RawObject formatIntOctal(Thread* thread, const Int& value, FormatSpec* format);
53
54// Format int as octal number with `0o` prefix. Returns a `str`.
55RawObject formatIntOctalSimple(Thread* thread, const Int& value);
56
57// Format double as hexadecimal number with `0x` prefix. Returns a `str`.
58RawObject formatDoubleHexadecimalSimple(Runtime* runtime, double value);
59
60RawObject formatStr(Thread* thread, const Str& str, FormatSpec* format);
61
62RawObject parseFormatSpec(Thread* thread, const Str& spec, int32_t default_type,
63 char default_align, FormatSpec* result);
64
65RawObject raiseUnknownFormatError(Thread* thread, int32_t format_code,
66 const Object& object);
67
68} // namespace py