Skip to content

Commit f7ce90b

Browse files
committed
readme refreshed
1 parent a7fd27f commit f7ce90b

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

README.md

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44

5-
> Important: We recommend upgrading to `1.4.1` (or `1.3.2+`: it introduced an important fix in floats formatting).
5+
> Important: Version 1.4.7 is built with kotlin 1.9 and is compatible with ALL KMP platforms including experimentlas wasmJS.
66
7-
Kotlin Multiplatform (also KMM) important missing tools, like sprintf with wide variety of formats, portable base64
7+
Kotlin Multiplatform important missing tools, like sprintf with wide variety of formats, portable base64
88

99
# Why reinventing the wheel?
1010

@@ -17,13 +17,16 @@ Please help me if you like the idea ;)
1717

1818
## In short, this library provides:
1919

20-
All 3 platforms:
20+
All platforms (macosX64, macosArm64, iosX64, iosArm64, iosSimulatorArm64,
21+
linuxX6, mingwX64, JVM, JS, wasmJS), in the same way:
2122

22-
- __Boyer-Moore based fast__ `ByteArray.indexOf`
2323

24-
- `Stirng.sprintf` - something like C `sprinf` or JVM String.format but extended and multiplatform
24+
- `Stirng.sprintf` - something like C `sprinf` or JVM `String.format` but with more features and multiplatform
25+
2526
- base64: `ByteArray.encodeToBase64()`, `ByteArray.encodeToBase64Compact()`, `String.decodeBase64()` and `ByteArray.decodeBase64Compact()`. Also URL-friendly forms: `ByteArray.encodeToBase64Url` and `String.decodeBase64Url`.
2627

28+
- Boyer-Moore based fast `ByteArray.indexOf`
29+
2730
- ByteArray tools: `getInt`, `putInt` and fast `indexOf`
2831
- Tools to cache recalculable expressions: `CachedRefreshingValue`, `CachedExpression` and `CachedSyncExpression` for JVM (as a good multithreading is there)
2932
- Missing `ReenterantMutex` for coroutines
@@ -48,24 +51,24 @@ dependencies {
4851
//...
4952
// see versions explained below, use latest release from
5053
// 'releases' or whatever you need:
51-
implementation("net.sergeych:mp_stools:1.4.1")
54+
implementation("net.sergeych:mp_stools:1.4.7")
5255
}
5356
~~~
5457

55-
that's all. Now you have working `sprintf` on every MP platform ;)
58+
That's all. Now you have working `sprintf` on every KMP platform ;)
5659

5760
# String tools:
5861

5962
## printf / sprintf!
6063

61-
The most popular and knonwn stromg format tool exists only on late JVM platform, so I reimplement it in
62-
platofrm-portable way. Here are some examples, the reference is below it. We reporoduce
63-
the [Java 11 String.format() notation](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Formatter)
64+
The most popular and known stromg format tool exists only on the modern JVM platforms,
65+
so I reimplement it in a platform-independent way.
66+
Here are some examples, the reference is below it.
67+
I reporoduced the [Java 11 String.format() notation](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Formatter)
6468
as much as possible, with the following notable differences:
6569

66-
- for argument number (`%1$12s`) is is possible also to use `!` instead of `$` (as the latter should be escaped in
67-
kotlin), e.g. `%1!12s` in that case is _also valid_
68-
- date/time per-plaftorm locales are not yet supported, everything is in English
70+
- for argument number (`%1$12s`) is possible also to use `!` instead of `$` (as the latter should be escaped in kotlin), e.g. `%1!12s` in that case is _also valid_
71+
- date/time per-platform locales are not yet supported, everything is in English
6972
- time zone abbreviations are missing (system returns valid tz id like +01:00 instead), as kotlinx.time does not
7073
provide (yet?)
7174

@@ -151,20 +154,20 @@ assertEquals("00221.1", "%07.1f".sprintf(221.1217))
151154

152155
### Safety notes
153156

154-
This sprintf/format implementation is safe on all platforms as it has not dependencies except
155-
standard `Number.toString()` wich is presumably safe. Despite of its name it does not call `C` library, uses controlled
156-
memory allocation and could not provide ovverruns (as kotlin arrays are all checked).
157+
This sprintf/format implementation is safe on all platforms
158+
as it has no dependencies except standard `Number.toString()`,
159+
which is presumably safe.
160+
Despite its name, it does not call `C` library,
161+
uses controlled memory allocation and could not provide overruns, as kotlin arrays are all checked.
157162

158163
### Sprintf syntax summary
159164

160-
Generic fields has the following notation:
165+
Generic format field has the following notation:
161166

162167
%[flags][size][.decimals]<format>
163168

164169
flags and size are optional, there could be several flags. The size field is used to pad the result to specified size,
165-
padding is added with spaces before the value by default, this behavior could be changed with flags, see
166-
below. `decimals` where applicable takes precedence over size, and determine how many decimal digits will be included,
167-
e.g. `"%.3f".sprintf(1) == "1.000"`
170+
padding is added with spaces before the value by default; this behavior could be changed with flags, see below. `decimals` where applicable takes precedence over size, and determines how many decimal digits will be included, e.g. `"%.3f".sprintf(1) == "1.000"`
168171

169172
If the argument is wider than the `size`, it is inserted as it is ignoring positioning flags and `size` field.
170173

@@ -204,12 +207,12 @@ We support
204207
the [Java 11 String.format() notation](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Formatter.html#syntax)
205208
as much as possible here too.
206209

207-
To format a time object it is possible to use:
210+
To format a time object, it is possible to use:
208211

209212
- multiplatform (recommended!) `kotlinx.datetime` classes: `Instant` and `LocalDateTime`.
210213
- on JS platoform also javascript `Date` class instances are also ok
211214
- on JVM platofm you can also use `java.time` classes: `java.time.Instant`, java.time.LocalDateTime` and `
212-
java.time.ZonedDateTime` as well. Zoned date time will be converted to system default time zone (e.g. its time zone
215+
java.time.ZonedDateTime` as well. Zoned date time will be converted to the system's default time zone (e.g., its time zone
213216
information will be lost).
214217

215218
Supported are all standard format specifiers.
@@ -277,10 +280,13 @@ confuse._
277280

278281
## Base64
279282

280-
Why? Simply because under JS there is no "good" way to convert to/from ByteArray (or Uint8Array) that works well
281-
everywhere, does not require NPM dependencies, work synchronously (I know how it could be made almost portable with
282-
promises) and in a correct way everywhere. So the wheel is reinvented again and works same kotlin-way on all 3
283-
platforms:
283+
Why?
284+
Because, for example, in JS,
285+
there is no good way to convert to/from ByteArray
286+
(or Uint8Array)that always works well and does not require NPM dependencies that work synchronously.
287+
288+
I know how it could be made almost portable with promises, though. So, here is an implementation that works well everywhere with the same interface.
289+
The wheel is reinvented one more time.
284290

285291
~~~
286292
val src = byteArrayOf(1,3,4,4)

0 commit comments

Comments
 (0)