-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Peanuuutz/dev
Add initial support for sequential parsing.
- Loading branch information
Showing
13 changed files
with
1,420 additions
and
903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/commonMain/kotlin/net/peanuuutz/tomlkt/TomlReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2023 Peanuuutz | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package net.peanuuutz.tomlkt | ||
|
||
/** | ||
* A custom reader used when decoding TOML file. | ||
* | ||
* @see TomlStringReader | ||
*/ | ||
public interface TomlReader { | ||
/** | ||
* Reads a single character and returns its [code], or returns -1 if EOF is | ||
* met. | ||
*/ | ||
public fun read(): Int | ||
} |
41 changes: 41 additions & 0 deletions
41
core/src/commonMain/kotlin/net/peanuuutz/tomlkt/TomlStringReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2023 Peanuuutz | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package net.peanuuutz.tomlkt | ||
|
||
/** | ||
* A [TomlReader] that reads TOML string. | ||
* | ||
* This reader is NOT thread-safe, so any concurrent usage should be avoided. | ||
* | ||
* Use with [Toml.decodeFromReader] to decode objects. Note that it is more | ||
* preferable to use [Toml.decodeFromString] directly as the reader is | ||
* disposable and should not be used twice. | ||
*/ | ||
public class TomlStringReader( | ||
private val source: String | ||
) : TomlReader { | ||
private val length: Int = source.length | ||
|
||
private var currentIndex: Int = 0 | ||
|
||
override fun read(): Int { | ||
if (currentIndex >= length) { | ||
return -1 | ||
} | ||
return source[currentIndex++].code | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
core/src/commonMain/kotlin/net/peanuuutz/tomlkt/internal/BufferUtils.common.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2023 Peanuuutz | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package net.peanuuutz.tomlkt.internal | ||
|
||
// No way a number reach this big... | ||
internal const val BufferSize: Int = 1 * 64 | ||
|
||
internal expect object BufferPool { | ||
fun take(): CharArray | ||
|
||
fun release(buffer: CharArray) | ||
} |
Oops, something went wrong.