Skip to content

Commit 396729f

Browse files
Use std::format() API now, instead of fmtlib
Signed-off-by: Christian Parpart <christian@parpart.family>
1 parent fb396b8 commit 396729f

19 files changed

+93
-143
lines changed

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Checks: >-
1515
UseColor: true
1616
WarningsAsErrors: true
1717
HeaderFilterRegex: ''
18-
AnalyzeTemporaryDtors: false
1918
FormatStyle: none
2019
CheckOptions:
2120
- key: bugprone-easily-swappable-parameters.MinimumLength

.github/workflows/build.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
fail-fast: false
3232
matrix:
33-
os_version: ['20.04', '22.04', '24.04']
33+
os_version: ['24.04']
3434
name: "Ubuntu ${{ matrix.os_version }}"
3535
runs-on: ubuntu-${{ matrix.os_version }}
3636
steps:
@@ -44,8 +44,6 @@ jobs:
4444
run: sudo apt -q update
4545
- name: "install dependencies"
4646
run: ./scripts/install-deps.sh
47-
- name: "create build directory"
48-
run: mkdir build
4947
- name: "cmake"
5048
run: |
5149
cmake -S . -B build -G Ninja \
@@ -77,8 +75,6 @@ jobs:
7775
set -ex
7876
#brew update
7977
./scripts/install-deps.sh
80-
- name: "Create build directory"
81-
run: mkdir build
8278
- name: "Generate build files"
8379
run: cmake --preset macos-release
8480
- name: "Build"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/out/
33
/_deps/
44
/_ucd/
5+
/.cache/
56
/.clangd/
67
/compile_commands.json
78
/.vscode/

cmake/ThirdParties.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ if(LIBUNICODE_BENCHMARK)
5454
endif()
5555

5656

57-
if(TARGET fmt)
58-
set(THIRDPARTY_BUILTIN_fmt "embedded")
59-
else()
60-
find_package(fmt REQUIRED)
61-
set(THIRDPARTY_BUILTIN_fmt "system package")
62-
endif()
63-
6457
macro(ThirdPartiesSummary2)
6558
message(STATUS "==============================================================================")
6659
message(STATUS " ThirdParties")
@@ -71,6 +64,5 @@ endif()
7164
if(LIBUNICODE_BENCHMARK)
7265
message(STATUS "Benchmark ${THIRDPARTY_BUILTIN_benchmark}")
7366
endif()
74-
message(STATUS "fmt ${THIRDPARTY_BUILTIN_fmt}")
7567
message(STATUS "------------------------------------------------------------------------------")
7668
endmacro()

scripts/install-deps.sh

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ fetch_and_unpack_benchmark()
7979
}
8080

8181

82-
fetch_and_unpack_fmtlib()
83-
{
84-
fetch_and_unpack \
85-
fmt-9.1.0 \
86-
fmtlib-9.1.0.tar.gz \
87-
https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.tar.gz
88-
}
89-
9082
prepare_fetch_and_unpack()
9183
{
9284
mkdir -p "${SYSDEPS_BASE_DIR}"
@@ -105,7 +97,6 @@ install_deps_ubuntu()
10597
cmake
10698
debhelper
10799
dpkg-dev
108-
g++
109100
libc6-dev
110101
make
111102
ninja-build
@@ -116,12 +107,13 @@ install_deps_ubuntu()
116107
local NAME=`grep ^NAME /etc/os-release | cut -d= -f2 | cut -f1 | tr -d '"'`
117108

118109
case $RELEASE in
119-
"20.04" | "22.04" | "24.04")
120-
fetch_and_unpack_fmtlib
110+
"24.04")
121111
fetch_and_unpack_Catch2
112+
packages="$packages g++-14"
122113
;;
123114
*)
124-
packages="$packages libfmt-dev catch2"
115+
packages="$packages g++"
116+
packages="$packages catch2"
125117
;;
126118
esac
127119

@@ -142,7 +134,6 @@ install_deps_FreeBSD()
142134
su root -c "pkg install $SYSDEP_ASSUME_YES \
143135
catch \
144136
cmake \
145-
libfmt \
146137
ninja \
147138
pkgconf \
148139
range-v3
@@ -151,7 +142,6 @@ install_deps_FreeBSD()
151142

152143
install_deps_arch()
153144
{
154-
fetch_and_unpack_fmtlib
155145
fetch_and_unpack_benchmark
156146
[ x$PREPARE_ONLY_EMBEDS = xON ] && return
157147

@@ -170,7 +160,6 @@ install_deps_fedora()
170160
local packages="
171161
catch-devel
172162
cmake
173-
fmt-devel
174163
gcc-c++
175164
google-benchmark-devel
176165
ninja-build
@@ -193,7 +182,6 @@ install_deps_darwin()
193182
# NB: Also available in brew: mimalloc
194183
# catch2: available in brew, but too new (version 3+)
195184
brew install $SYSDEP_ASSUME_YES \
196-
fmt \
197185
ninja \
198186
pkg-config \
199187
range-v3
@@ -230,7 +218,6 @@ main()
230218
;;
231219
*)
232220
fetch_and_unpack_Catch2
233-
fetch_and_unpack_fmtlib
234221
fetch_and_unpack_benchmark
235222
echo "OS $ID not supported."
236223
echo "Dependencies were fetch manually and most likely libunicode will compile."

src/libunicode/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ if(LIBUNICODE_TESTING)
242242
target_include_directories(Catch2 SYSTEM INTERFACE ${CATCH2_INCLUDE_DIRS})
243243
endif()
244244

245-
target_link_libraries(unicode_test unicode Catch2::Catch2WithMain fmt::fmt-header-only)
245+
target_link_libraries(unicode_test unicode Catch2::Catch2WithMain)
246246
add_test(unicode_test unicode_test)
247247
endif()
248248
# }}}

src/libunicode/capi_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
*/
1414
#include <libunicode/capi.h>
1515

16-
#include <fmt/format.h>
17-
1816
#include <catch2/catch_test_macros.hpp>
1917

2018
#include <array>
19+
#include <format>
2120
#include <utility>
2221

2322
using namespace std;

src/libunicode/convert_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
#include <libunicode/support.h>
1616
#include <libunicode/utf8.h>
1717

18-
#include <fmt/format.h>
19-
2018
#include <catch2/catch_test_macros.hpp>
2119

20+
#include <format>
2221
#include <iterator>
2322

2423
using namespace unicode;

src/libunicode/emoji_segmenter.h

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
#include <libunicode/support.h>
1717

18-
#include <algorithm>
19-
#include <array>
18+
#include <format>
2019
#include <ostream>
21-
#include <utility>
2220

2321
namespace unicode
2422
{
@@ -129,7 +127,6 @@ inline std::ostream& operator<<(std::ostream& os, EmojiSegmentationCategory valu
129127
{
130128
switch (value)
131129
{
132-
// clang-format off
133130
case unicode::EmojiSegmentationCategory::Invalid: return os << "Invalid";
134131
case unicode::EmojiSegmentationCategory::Emoji: return os << "Emoji";
135132
case unicode::EmojiSegmentationCategory::EmojiTextPresentation: return os << "EmojiTextPresentation";
@@ -140,66 +137,62 @@ inline std::ostream& operator<<(std::ostream& os, EmojiSegmentationCategory valu
140137
case unicode::EmojiSegmentationCategory::RegionalIndicator: return os << "RegionalIndicator";
141138
case unicode::EmojiSegmentationCategory::KeyCapBase: return os << "KeyCapBase";
142139
case unicode::EmojiSegmentationCategory::CombiningEnclosingKeyCap: return os << "CombiningEnclosingKeyCap";
143-
case unicode::EmojiSegmentationCategory::CombiningEnclosingCircleBackslash: return os << "CombiningEnclosingCircleBackslash";
140+
case unicode::EmojiSegmentationCategory::CombiningEnclosingCircleBackslash:
141+
return os << "CombiningEnclosingCircleBackslash";
144142
case unicode::EmojiSegmentationCategory::ZWJ: return os << "ZWJ";
145143
case unicode::EmojiSegmentationCategory::VS15: return os << "VS15";
146144
case unicode::EmojiSegmentationCategory::VS16: return os << "VS16";
147145
case unicode::EmojiSegmentationCategory::TagBase: return os << "TagBase";
148146
case unicode::EmojiSegmentationCategory::TagSequence: return os << "TagSequence";
149147
case unicode::EmojiSegmentationCategory::TagTerm: return os << "TagTerm";
150-
// clang-format off
151148
}
152149
return os;
153150
}
154151

155152
} // namespace unicode
156153

157-
// clang-format off
158-
#if __has_include(<fmt/ostream.h>)
159-
#include <fmt/ostream.h>
160-
#if FMT_VERSION >= (9 * 10000 + 1 * 100 + 0)
161-
template <> struct fmt::formatter<unicode::PresentationStyle>: fmt::ostream_formatter {};
162-
163-
164-
namespace fmt
165-
{
166154
template <>
167-
struct formatter<unicode::EmojiSegmentationCategory>
155+
struct std::formatter<unicode::PresentationStyle>: std::formatter<std::string_view>
168156
{
169-
template <typename ParseContext>
170-
constexpr auto parse(ParseContext& ctx)
157+
auto format(unicode::PresentationStyle value, auto& ctx) const
171158
{
172-
return ctx.begin();
159+
string_view name;
160+
switch (value)
161+
{
162+
case unicode::PresentationStyle::Text: name = "Text"; break;
163+
case unicode::PresentationStyle::Emoji: name = "Emoji"; break;
164+
}
165+
return formatter<string_view>::format(name, ctx);
173166
}
174-
template <typename FormatContext>
175-
auto format(unicode::EmojiSegmentationCategory value, FormatContext& ctx)
167+
};
168+
169+
template <>
170+
struct std::formatter<unicode::EmojiSegmentationCategory>: std::formatter<std::string_view>
171+
{
172+
auto format(unicode::EmojiSegmentationCategory value, auto& ctx) const
176173
{
174+
using unicode::EmojiSegmentationCategory;
175+
string_view name;
177176
switch (value)
178177
{
179-
// clang-format off
180-
case unicode::EmojiSegmentationCategory::Invalid: return fmt::format_to(ctx.out(), "Invalid");
181-
case unicode::EmojiSegmentationCategory::Emoji: return fmt::format_to(ctx.out(), "Emoji");
182-
case unicode::EmojiSegmentationCategory::EmojiTextPresentation: return fmt::format_to(ctx.out(), "EmojiTextPresentation");
183-
case unicode::EmojiSegmentationCategory::EmojiEmojiPresentation: return fmt::format_to(ctx.out(), "EmojiEmojiPresentation");
184-
case unicode::EmojiSegmentationCategory::EmojiModifierBase: return fmt::format_to(ctx.out(), "EmojiModifierBase");
185-
case unicode::EmojiSegmentationCategory::EmojiModifier: return fmt::format_to(ctx.out(), "EmojiModifier");
186-
case unicode::EmojiSegmentationCategory::EmojiVSBase: return fmt::format_to(ctx.out(), "EmojiVSBase");
187-
case unicode::EmojiSegmentationCategory::RegionalIndicator: return fmt::format_to(ctx.out(), "RegionalIndicator");
188-
case unicode::EmojiSegmentationCategory::KeyCapBase: return fmt::format_to(ctx.out(), "KeyCapBase");
189-
case unicode::EmojiSegmentationCategory::CombiningEnclosingKeyCap: return fmt::format_to(ctx.out(), "CombiningEnclosingKeyCap");
190-
case unicode::EmojiSegmentationCategory::CombiningEnclosingCircleBackslash: return fmt::format_to(ctx.out(), "CombiningEnclosingCircleBackslash");
191-
case unicode::EmojiSegmentationCategory::ZWJ: return fmt::format_to(ctx.out(), "ZWJ");
192-
case unicode::EmojiSegmentationCategory::VS15: return fmt::format_to(ctx.out(), "VS15");
193-
case unicode::EmojiSegmentationCategory::VS16: return fmt::format_to(ctx.out(), "VS16");
194-
case unicode::EmojiSegmentationCategory::TagBase: return fmt::format_to(ctx.out(), "TagBase");
195-
case unicode::EmojiSegmentationCategory::TagSequence: return fmt::format_to(ctx.out(), "TagSequence");
196-
case unicode::EmojiSegmentationCategory::TagTerm: return fmt::format_to(ctx.out(), "TagTerm");
197-
// clang-format off
178+
case EmojiSegmentationCategory::Invalid: name = "Invalid"; break;
179+
case EmojiSegmentationCategory::Emoji: name = "Emoji"; break;
180+
case EmojiSegmentationCategory::EmojiTextPresentation: name = "EmojiTextPresentation"; break;
181+
case EmojiSegmentationCategory::EmojiEmojiPresentation: name = "EmojiEmojiPresentation"; break;
182+
case EmojiSegmentationCategory::EmojiModifierBase: name = "EmojiModifierBase"; break;
183+
case EmojiSegmentationCategory::EmojiModifier: name = "EmojiModifier"; break;
184+
case EmojiSegmentationCategory::EmojiVSBase: name = "EmojiVSBase"; break;
185+
case EmojiSegmentationCategory::RegionalIndicator: name = "RegionalIndicator"; break;
186+
case EmojiSegmentationCategory::KeyCapBase: name = "KeyCapBase"; break;
187+
case EmojiSegmentationCategory::CombiningEnclosingKeyCap: name = "CombiningEnclosingKeyCap"; break;
188+
case EmojiSegmentationCategory::CombiningEnclosingCircleBackslash: name = "CombiningEnclosingCircleBackslash"; break;
189+
case EmojiSegmentationCategory::ZWJ: name = "ZWJ"; break;
190+
case EmojiSegmentationCategory::VS15: name = "VS15"; break;
191+
case EmojiSegmentationCategory::VS16: name = "VS16"; break;
192+
case EmojiSegmentationCategory::TagBase: name = "TagBase"; break;
193+
case EmojiSegmentationCategory::TagSequence: name = "TagSequence"; break;
194+
case EmojiSegmentationCategory::TagTerm: name = "TagTerm"; break;
198195
}
199-
return fmt::format_to(ctx.out(), "({})", unsigned(value));
200-
}
196+
return formatter<string_view>::format(name, ctx);
197+
}
201198
};
202-
}
203-
#endif
204-
#endif
205-
// clang-format on

src/libunicode/emoji_segmenter_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#include <libunicode/run_segmenter.h>
1717
#include <libunicode/utf8.h>
1818

19-
#include <fmt/format.h>
20-
2119
#include <catch2/catch_test_macros.hpp>
2220

21+
#include <format>
22+
2323
using namespace unicode;
2424
using namespace std::string_literals;
2525
using namespace std;
@@ -46,14 +46,14 @@ void test_segments(int lineNo, std::vector<std::pair<std::u32string_view, Presen
4646
i += text.size();
4747
}
4848

49-
INFO(fmt::format("Testing emoji segmentation from line {}: {}", lineNo, to_utf8(fullText)));
49+
INFO(std::format("Testing emoji segmentation from line {}: {}", lineNo, to_utf8(fullText)));
5050

5151
size_t size {};
5252
auto presentationStyle = PresentationStyle {};
5353
auto segmenter = unicode::emoji_segmenter { fullText };
5454
for (size_t i = 0; i < expectations.size(); ++i)
5555
{
56-
INFO(fmt::format("run segmentation for part {}: \"{}\" to be {}",
56+
INFO(std::format("run segmentation for part {}: \"{}\" to be {}",
5757
i,
5858
to_utf8(expectations[i].first),
5959
(unsigned) expectations[i].second));

0 commit comments

Comments
 (0)