summaryrefslogtreecommitdiff
path: root/AK/Format.cpp
AgeCommit message (Collapse)Author
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.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-13AK+Format: Don't cast to size_t when you want u64.Paul Scharnofske
In Serenity, size_t is defined as u32, thus static_cast<size_t>(value) truncates the value.
2021-02-08Everywhere: Remove unnecessary headers 1/4Ben Wiederhake
Arbitrarily split up to make git bisect easier. These unnecessary #include's were found by combining an automated tool (which determined likely candidates) and some brain power (which decided whether the #include is also semantically superfluous). My favorite #include: #include "Applications/Piano/Music.h" // You can't have too much music in life!
2021-01-27AK: Include the processor id in log messagesTom
2021-01-23AK+Format: Add dmesgln() to replace klog().asynts
2021-01-22AK: Add set_debug_enabled method.asynts
2021-01-09AK: Add Formatter<FormatString> as helper class.asynts
2020-12-30AK+Format: Remove TypeErasedFormatParams& from format function.asynts
2020-12-06AK: Make Formatter<StringView> not choke on Mode::CharacterLinus Groh
Formatter<char> internally uses Formatter<StringView> when in Mode::Character, but that would only accept Mode::{Default,String} and ASSERT_NOT_REACHED() otherwise, causing String::formatted("{:c}", 'a') to crash
2020-11-09AK: Add formatters for floating point numbers.asynts
2020-10-17AK+Format: Add outln(FILE*, ...) overload.asynts
This commit also removes a few functions like raw_out and vwarn. If we want to write raw output, we can do this as follows: out("{}", "Hello, World!"); The vout stuff isn't really public API anyways, so no need for another vwarn.
2020-10-09AK+Format: Remove new_dbg(dbg) and raw_dbg.asynts
We are adding the process name as prefix and a newline as suffix to any message written to debug. Thus, the following doesn't make any sense: for (u8 byte : bytes) dbg("{:02x} ", byte); dbgln(); Which function call would put the prefix? This doesn't make any sense, thus these functions must go. The example above could be converted to: StringBuilder builder; for (u8 byte : bytes) builder.appendff("{:02x} ", byte); dbgln("{}", builder.build());
2020-10-08AK: Use new format functions.asynts
2020-10-08AK+Format: Make it possible to format characters as integers.asynts
2020-10-08Formatter: Remove extraneous char definitionLenny Maiorani
Formatter is specialized in the header file. The definition in the implementation file is extraneous and has no effect. Simply removing it so that there is no confusion.