summaryrefslogtreecommitdiff
path: root/AK/Format.cpp
AgeCommit message (Collapse)Author
2023-06-04Kernel: Move all tasks-related code to the Tasks subdirectoryLiav A
2023-05-24Everywhere: Use MonotonicTime instead of Durationkleines Filmröllchen
This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
2023-05-18AK: Add dbg()Nico Weber
We have outln() and out(), warnln() and warn(), now we have dbgln() and dbg(). This is useful for printing arrays element-by-element while still only printing one line per array.
2023-04-11AK: Add option to the string formatter to use a digit separatorTim Ledbetter
`vformat()` can now accept format specifiers of the form {:'[numeric-type]}. This will output a number with a comma separator every 3 digits. For example: `dbgln("{:'d}", 9999999);` will output 9,999,999. Binary, octal and hexadecimal numbers can also use this feature, for example: `dbgln("{:'x}", 0xffffffff);` will output ff,fff,fff.
2023-02-24AK+Kernel: Add includes before removing Kernel/ProcessExposed.hLiav A
Apparently without this file, we won't be able to compile due to missing includes to TimeManagement and KBufferBuilder.
2023-02-18AK: Fix printing of negative FixedPoint valuesNico Weber
Fixes #17514 by comparing to 0 before truncating the fractional part.
2023-02-06Kernel: Protect Process::m_name with a spinlockSam Atkins
This also lets us remove the `get_process_name` and `set_process_name` syscalls from the big lock. :^)
2023-01-24AK: Print leading zeroes after the dot for FixedPoint numbersNico Weber
As a nearby comment says, "This is a terrible approximation". This doesn't make things less terrible, but it does make things more correct in the given framework of terribleness. Fixes #17156.
2023-01-18AK: Unify kernel debug messages, avoid printing time if unavailablekonrad
2023-01-06AK: Support fixed point formatting to print real numbersLucas CHOLLET
2023-01-06AK: Rename `StandardFormatter::Mode::Float` => `FixedPoint`Lucas CHOLLET
2022-12-11AK: Allow non-ascii characters to be printedAli Mohammad Pur
This keeps the FIXME, as well as the assertion.
2022-12-11AK: Ignore "alternative" formatting of StringView instead of crashingAli Mohammad Pur
Jakt implements this in a different way, but it's a noop for StringViews anyway.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-10-17Kernel/aarch64: Initialize TimeManagement in init.cppTimon Kruiper
Also remove the check for aarch64 in AK/Format.cpp, so now the format functions will prepend the time since boot!
2022-10-10Everywhere: Replace uses of __serenity__ with AK_OS_SERENITYAndrew Kaster
Now that we have OS macros for essentially every supported OS, let's try to use them everywhere.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-17Everywhere: Switch from EnableIf to requiresLenny Maiorani
C++20 provides the `requires` clause which simplifies the ability to limit overload resolution. Prefer it over `EnableIf` With all uses of `EnableIf` being removed, also remove the implementation so future devs are not tempted.
2022-02-16AK: Use string_view() instead of to_string() in Formatter<wchar_t>Idan Horowitz
This let's us avoid a heap allocation.
2022-02-06AK: Use integral power for FixedPoint formattingHendiadyoin1
This removes an ifdef for the Kernel
2022-01-23AK: Add Formatter<FixedPoint<...>> without floating pointTom
Rather than casting the FixedPoint to double, format the FixedPoint directly. This avoids using floating point instruction, which in turn enables this to be used even in the kernel.
2021-11-21Kernel: Wrap format timespec assignment in a check for !AARCH64James Mintram
Currently TimeManagement wont compile on AARCH64, so it is not included. This creates a link error since format.cpp now relies on functionality in TimeManagement.cpp to add timestamps to log lines. This PR disables that functionality for AARCH64 builds until TimeManagement will compile.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-10-31AK+Tests: Fix formatting of infinity and NaN valuesDaniel Bertalan
When I added this code in 1472f6d, I forgot to add tests for it. That's why I didn't realize that the values were appended to the wrong FormatBuilder object, so an empty string was returned instead of the expected "nan"/"inf". This made debugging some FPU issues with the ScummVM port significantly more difficult.
2021-10-26AK: Prefix debug log messages with current-time-since-bootAndreas Kling
This is very helpful when trying to better understand how long certain things take. :^)
2021-10-21AK: Avoid temporary String allocation in Formatter<FormatString>Daniel Bertalan
Creating a String object from the formatted data is unnecessary, as it immediately gets turned into a StringView anyways. With this change, we will no longer allocate on the heap when printing `VirtualAddress`, `VirtualRange` and `InodeIdentifier` objects, which is a step towards stronger OOM hardening.
2021-10-03AK: Add a basic formatter for wchar_tTim Schumacher
2021-09-10Kernel: Add kernelearlyputstr and use it in dbgln in very-early bootIdan Horowitz
This variant of dbgputstr does not lock the global log lock, as it is called before the current or any other processor was initialized, meaning that: A) The $gs base was not setup yet, so we cannot enter into critical sections, and as a result we cannot use SpinLocks B) No other processors may try to print at the same time anyway
2021-09-10AK: Only try and get the Processor::current_id when it was initializedIdan Horowitz
This caused a null pointer dereference on early boot, since the gs_base was not set yet.
2021-09-07Everywhere: Behaviour => BehaviorAndreas Kling
2021-08-30Everywhere: Pass AK::Format TypeErasedFormatParams by referenceBrian Gianforcaro
This silences a overeager warning in sonar cloud, warning that slicing could occur with `VariadicFormatParams` which derives from `TypeErasedFormatParams`. Reference: https://sonarcloud.io/project/issues?id=SerenityOS_serenity&issues=AXuVPBO_k92xXUF3qWsm&open=AXuVPBO_k92xXUF3qWsm
2021-08-23Kernel: Rename Processor::id() => current_id()Andreas Kling
And let id() be the non-static version that gives you the ID of a Processor object.
2021-08-19AK: Move FormatParser definition from header to implementation fileTimothy Flynn
This is primarily to be able to remove the GenericLexer include out of Format.h as well. A subsequent commit will add AK::Result to GenericLexer, which will cause naming conflicts with other structures named Result. This can be avoided (for now) by preventing nearly every file in the system from implicitly including GenericLexer. Other changes in this commit are to add the GenericLexer include to files where it is missing.
2021-08-08AK: Add formatting for infinity and NaNDaniel Bertalan
Without this patch, we would end up printing garbage values when we encountered floating point infinity or NaN values, and also triggered UBSAN with Clang. This added code models `std::format`'s behavior: the sign is added the same way as with normal values and the strings 'nan' and 'inf' are printed.
2021-07-19AK: Use StringView literals in Format to avoid strlenAndrew Kaster
We don't want to be constructing StringViews at runtime if we don't have to in Formatter code.
2021-07-18AK: Allow setting both width and precision when formatting a stringTimothy Flynn
2021-07-08Everywhere: Use the correct literal suffixesDaniel Bertalan
When performing arithmetic with long doubles/floats, we want to avoid floating point promotion and narrowing.
2021-07-07AK: Replace usages of ctype.h with CharacterTypes.hMax Wipfli
This replaces all remaining usages of ctype.h in AK with CharacterTypes.h.
2021-07-02AK: Support long doubles in format stringsHediadyoin1
2021-06-19AK: Add support for keeping trailing zeros in fixed precision floatsIdan Horowitz
This uses the same syntax as zero padding integers: String::formatted("{:0.5}", 1.234) => "1.23400"
2021-06-17AK: Add a :hex-dump mode to AK::FormatAli Mohammad Pur
This will just hexdump the given value. Note that not all formatters respect this, the ones that do are: - (Readonly)Bytes: formatter added in this commit - StringView / char const* - integral types
2021-05-19AK: Make vout() log to debug instead of VERIFY()'ingAli Mohammad Pur
In case the write was to stderr/stdout, and it just so happened to fail because of an issue like "the pty is gone", VERIFY() would end up calling vout() back to write to stderr, which would then fail forever until the stack is exhausted. "Fixes" the issue where the Shell would crash in horrible ways when the terminal is closed.
2021-05-16Kernel/Graphics + SystemServer: Support text mode properlyLiav A
As we removed the support of VBE modesetting that was done by GRUB early on boot, we need to determine if we can modeset the resolution with our drivers, and if not, we should enable text mode and ensure that SystemServer knows about it too. Also, SystemServer should first check if there's a framebuffer device node, which is an indication that text mode was not even if it was requested. Then, if it doesn't find it, it should check what boot_mode argument the user specified (in case it's self-test). This way if we try to use bochs-display device (which is not VGA compatible) and request a text mode, it will not honor the request and will continue with graphical mode. Also try to print critical messages with mininum memory allocations possible. In LibVT, We make the implementation flexible for kernel-specific methods that are implemented in ConsoleImpl class.
2021-04-29AK: Make dbgln log the thread IDGunnar Beutner
This makes debugging multi-threaded programs easier.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-21AK/Format: Compute TypeErasedParameter type and size at compile-timeLenny Maiorani
Problem: - Type and size information is known at compile-time, but computations are being performed using run-time parameters. Solution: - Move function arguments to be template arguments. - Convert to `consteval` where possible. - Decorate functions with `constexpr` which are used in both run-time and compile-time contexts.
2021-04-16AK: Fix incorrect formatter signing of numbers between -1.0 and 0.0Matthew Olsson
Floating point numbers are casted to i64 and passed to the integer formatting logic, and the floating point portion of the number is handled separately. However, casting to i64 when the number is between -1.0 and 0.0 produces 0, so the sign would be lost. This commit fixes that by using put_u64 instead, which allows us to manually provide the is_negative flag.
2021-04-10AK+Everywhere: Make StdLibExtras templates less wrapper-yAnotherTest
This commit makes the user-facing StdLibExtras templates and utilities arguably more nice-looking by removing the need to reach into the wrapper structs generated by them to get the value/type needed. The C++ standard library had to invent `_v` and `_t` variants (likely because of backwards compat), but we don't need to cater to any codebase except our own, so might as well have good things for free. :^)
2021-04-08Format: Strip trailing zeroes from floating point valuesJelle Raaijmakers
This is a pretty naive implementation that works well. The precision parameter is interpreted as "maximum precision" instead of "minimum precision", which in my opinion is the most useful interpretation.