summaryrefslogtreecommitdiff
path: root/AK/Format.h
AgeCommit message (Collapse)Author
2021-01-23AK+Format: Add dmesgln() to replace klog().asynts
2021-01-22AK: Add set_debug_enabled method.asynts
2021-01-16AK: Add enabled template parameter to dbgln.asynts
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
2021-01-11Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.Everything:
2021-01-09AK: Add Formatter<FormatString> as helper class.asynts
2021-01-02Piggyback: AK: Add formatter for std::nullptr_t.asynts
2020-12-30AK+Format: Remove TypeErasedFormatParams& from format function.asynts
2020-12-29AK+Format: Accept unsigned long in replacement fields.asynts
I ran into this exact but at least twenty times in Serenity alone. The C++ Standard dictates that 'unsigned long' and 'unsigned long long' are distinct types even though on most platforms they are usually both 64 bit integers. Also it wasn't possible to evaluate IsIntegral<T> for types that were not integers since it used MakeUnsigned<T> internally.
2020-11-09AK: Add formatters for floating point numbers.asynts
2020-11-09AK: Rename new_out to out and new_warn to warn.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+Format: Make it possible to format characters as integers.asynts
2020-10-08AK+Format: Add SFINAE wrapper 'FormatIfSupported'.asynts
2020-10-08AK+Format: Add overloads with const char* for outln, warnln and dbgln.asynts
This makes it possible to forward declare 'warnln' in TestSuite.h.
2020-10-08AK+Format: Add overloads without arguments to outln, warnln and dbgln.asynts
2020-10-08AK+Format: Use pointer mode for pointers by default.asynts
2020-10-08VariadicFormatParams: Use initialized data to create parent classLenny Maiorani
Problem: - m_data is being passed to the constructor of the parent class before it is initialized. This is not really a problem because the compiler knows the location and it is only a span being constructed, but it triggers a warning in clang for use-before-init. Solution: - Initialize using a default constructed array and then overwrite it inside the constructor after the member is initialized.
2020-10-06AK+Format: Make it possible to format string literals as pointers.asynts
String literals are just pointers to a constant character. It should be possible to format them as such. (The default is to print them as strings still.)
2020-10-06AK+Format: Exclude prefix from width calculation.asynts
When we write the format specifier '{:#08x}' we are asking for eight significant digits, zero padding and the prefix '0x'. However, previously we got only six significant digits because the prefix counted towards the width. (The number '8' here is the total width and not the number of significant digits.) Both fmtlib and printf shared this behaviour. However, I am introducing a special case here because when we do zero padding we really only care about the digits and not the width. Notice that zero padding is a special case anyways, because zero padding goes after the prefix as opposed to any other padding which goes before it.
2020-10-04AK: Don't add newline for outf/dbgf/warnf.asynts
In the future all (normal) output should be written by any of the following functions: out (currently called new_out) outln dbg (currently called new_dbg) dbgln warn (currently called new_warn) warnln However, there are still a ton of uses of the old out/warn/dbg in the code base so the new functions are called new_out/new_warn/new_dbg. I am going to rename them as soon as all the other usages are gone (this might take a while.) I also added raw_out/raw_dbg/raw_warn which don't do any escaping, this should be useful if no formatting is required and if the input contains tons of curly braces. (I am not entirely sure if this function will stay, but I am adding it for now.)
2020-10-04AK: Add Formatter for FlyString :^)Andreas Kling
2020-10-04AK: Add special formatter for char.asynts
When we format a character we want to put the ascii value and not the decimal value. The old behaviour can be obtained with '{:d}'.
2020-10-02AK+Format: Do some housekeeping in the format implementation.asynts
2020-10-02AK: Add formatter for pointer types.asynts
2020-10-02AK: Add formatter for boolean values.asynts
2020-09-28AK+Format: Support default index in replacement field.asynts
The following does now work: outf("{:0{}}", 1, 3); // 001
2020-09-28AK+Format: Keep type information for integers in TypeErasedParameter.asynts
It's now save to pass a signed integer as parameter and then use it as replacement field (previously, this would just cast it to size_t which would be bad.)
2020-09-28AK+Format: Clean up format specifier parsing using GenericLexer.asynts
Also adds support for replacement fields.
2020-09-26AK+Format: Use the new format backend in the implementation.asynts
2020-09-26AK: Borrow exact format syntax form std::format.asynts
Instead of just implementing format specifiers ad-hog this commit implements the exact syntax std::format uses. There are still a ton of features that are not supported by this implementation, however, the format specifiers should be parsed correctly. In some cases however, the format specifiers aren't quite parsed correctly, for example: String::formatted("{:{}}", 42, 4) should produce the string " 42" however an (unrelated) assertion fails. This is because vformat doesn't consider nested parentheses. I have to spend some time coming up with a simple way of doing this, I don't feel like doing that right now. The fundamental code for this already exists, by limiting the number of format arguments (arbitrarily) to 256 large widths are used to encode that these should be taken from other format parameters.
2020-09-23Applications+IRCClient: Use new format functions.asynts
2020-09-23AK: Add outf, warnf and dbgf.asynts
2020-09-23AK: Resolve format related circular dependencies properly.asynts
With this commit, <AK/Format.h> has a more supportive role and isn't used directly. Essentially, there now is a public 'vformat' function ('v' for vector) which takes already type erased parameters. The name is choosen to indicate that this function behaves similar to C-style functions taking a va_list equivalent. The interface for frontend users are now 'String::formatted' and 'StringBuilder::appendff'.
2020-09-23AK: Allow calling format without arguments.asynts
2020-09-22AK: Add missing overload to format.asynts
I had this in #3580 but I must have lost it during rebasing.
2020-09-22AK: Add StringBuilder::appendff using the new format.asynts
StringBuilder::appendf was already used, thus this name. If we some day replace all usages of printf, we could rename this method.
2020-09-22AK: Remove strtoull dependency from format.asynts
This function is not avaliable in the kernel. In the future it would be nice to have some sort of <charconv> header that does this for all integer types and then call it in strtoull and et cetera. The difference would be that this function say 'from_chars' would return an Optional and not just interpret anything invalid as zero.
2020-09-21AK: Add format function like std::format or fmt::format.asynts