Skip to content

Commit 3d3f126

Browse files
authored
gh-139353: Rename formatter_unicode.c to unicode_formatter.c (#139723)
* Move Python/formatter_unicode.c to Objects/unicode_formatter.c. * Move Objects/stringlib/localeutil.h content into unicode_formatter.c. Remove localeutil.h. * Move _PyUnicode_InsertThousandsGrouping() to unicode_formatter.c and mark the function as static. * Rename unicode_fill() to _PyUnicode_Fill() and export it in pycore_unicodeobject.h. * Move MAX_UNICODE to pycore_unicodeobject.h as _Py_MAX_UNICODE.
1 parent 5cea843 commit 3d3f126

File tree

10 files changed

+293
-305
lines changed

10 files changed

+293
-305
lines changed

Include/internal/pycore_unicodeobject.h

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,44 @@ extern "C" {
1111
#include "pycore_fileutils.h" // _Py_error_handler
1212
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
1313

14+
// Maximum code point of Unicode 6.0: 0x10ffff (1,114,111).
15+
#define _Py_MAX_UNICODE 0x10ffff
16+
17+
18+
static inline void
19+
_PyUnicode_Fill(int kind, void *data, Py_UCS4 value,
20+
Py_ssize_t start, Py_ssize_t length)
21+
{
22+
assert(0 <= start);
23+
switch (kind) {
24+
case PyUnicode_1BYTE_KIND: {
25+
assert(value <= 0xff);
26+
Py_UCS1 ch = (unsigned char)value;
27+
Py_UCS1 *to = (Py_UCS1 *)data + start;
28+
memset(to, ch, length);
29+
break;
30+
}
31+
case PyUnicode_2BYTE_KIND: {
32+
assert(value <= 0xffff);
33+
Py_UCS2 ch = (Py_UCS2)value;
34+
Py_UCS2 *to = (Py_UCS2 *)data + start;
35+
const Py_UCS2 *end = to + length;
36+
for (; to < end; ++to) *to = ch;
37+
break;
38+
}
39+
case PyUnicode_4BYTE_KIND: {
40+
assert(value <= _Py_MAX_UNICODE);
41+
Py_UCS4 ch = value;
42+
Py_UCS4 * to = (Py_UCS4 *)data + start;
43+
const Py_UCS4 *end = to + length;
44+
for (; to < end; ++to) *to = ch;
45+
break;
46+
}
47+
default: Py_UNREACHABLE();
48+
}
49+
}
50+
51+
1452
/* --- Characters Type APIs ----------------------------------------------- */
1553

1654
extern int _PyUnicode_IsXidStart(Py_UCS4 ch);
@@ -240,21 +278,6 @@ extern PyObject* _PyUnicode_XStrip(
240278
);
241279

242280

243-
/* Using explicit passed-in values, insert the thousands grouping
244-
into the string pointed to by buffer. For the argument descriptions,
245-
see Objects/stringlib/localeutil.h */
246-
extern Py_ssize_t _PyUnicode_InsertThousandsGrouping(
247-
_PyUnicodeWriter *writer,
248-
Py_ssize_t n_buffer,
249-
PyObject *digits,
250-
Py_ssize_t d_pos,
251-
Py_ssize_t n_digits,
252-
Py_ssize_t min_width,
253-
const char *grouping,
254-
PyObject *thousands_sep,
255-
Py_UCS4 *maxchar,
256-
int forward);
257-
258281
/* Dedent a string.
259282
Behaviour is expected to be an exact match of `textwrap.dedent`.
260283
Return a new reference on success, NULL with exception set on error.

Makefile.pre.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ PYTHON_OBJS= \
501501
Python/pystrtod.o \
502502
Python/pystrhex.o \
503503
Python/dtoa.o \
504-
Python/formatter_unicode.o \
505504
Python/fileutils.o \
506505
Python/suggestions.o \
507506
Python/perf_trampoline.o \
@@ -558,6 +557,7 @@ OBJECT_OBJS= \
558557
Objects/tupleobject.o \
559558
Objects/typeobject.o \
560559
Objects/typevarobject.o \
560+
Objects/unicode_formatter.o \
561561
Objects/unicodeobject.o \
562562
Objects/unicodectype.o \
563563
Objects/unionobject.o \
@@ -2091,7 +2091,6 @@ UNICODE_DEPS = \
20912091
$(srcdir)/Objects/stringlib/fastsearch.h \
20922092
$(srcdir)/Objects/stringlib/find.h \
20932093
$(srcdir)/Objects/stringlib/find_max_char.h \
2094-
$(srcdir)/Objects/stringlib/localeutil.h \
20952094
$(srcdir)/Objects/stringlib/partition.h \
20962095
$(srcdir)/Objects/stringlib/replace.h \
20972096
$(srcdir)/Objects/stringlib/repr.h \

Objects/stringlib/localeutil.h

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)