-
Notifications
You must be signed in to change notification settings - Fork 177
Sprintf realization #4794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MrEx3cut0r
wants to merge
28
commits into
objectionary:master
Choose a base branch
from
MrEx3cut0r:Issue-4752
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Sprintf realization #4794
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9487e74
Sprintf realization
MrEx3cut0r af8998e
fix
MrEx3cut0r 5c9423c
fix
MrEx3cut0r 29cfeaa
fix
MrEx3cut0r c5105b3
fix
MrEx3cut0r 7ebbb32
fix
MrEx3cut0r f118c84
fix
MrEx3cut0r 9ac57a8
fix
MrEx3cut0r baf9882
fix
MrEx3cut0r 7e9442e
fix
MrEx3cut0r 37ec9fb
fix
MrEx3cut0r a0eba10
fix
MrEx3cut0r 08235f7
fix
MrEx3cut0r bfce50e
fix
MrEx3cut0r 4fa14f9
fix
MrEx3cut0r 0285e1e
fix
MrEx3cut0r 12c0843
fix
MrEx3cut0r 68598d4
fix
MrEx3cut0r 298837d
fix
MrEx3cut0r b89bb67
fix
MrEx3cut0r cb984df
fix
MrEx3cut0r 60b1ca4
fix
MrEx3cut0r 0468c29
fix
MrEx3cut0r 0e46279
fix
MrEx3cut0r 5e75bbe
fix
MrEx3cut0r 4fa9838
fix
MrEx3cut0r afa497f
fix
MrEx3cut0r c4d6eee
fix
MrEx3cut0r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,177 @@ | ||
| +home https://github.com/objectionary/eo | ||
| +package org.eolang.io | ||
| +version 0.0.0 | ||
| +alias org.eolang.txt.concat | ||
| +alias org.eolang.txt.split | ||
| +alias org.eolang.txt.at | ||
| +alias org.eolang.txt.substring | ||
| +alias org.eolang.txt.length | ||
| +alias org.eolang.seq | ||
| +alias org.eolang.array | ||
| +alias org.eolang.memory | ||
| +alias org.eolang.int.add | ||
| +alias org.eolang.int.sub | ||
| +alias org.eolang.int.mul | ||
| +alias org.eolang.int.div | ||
| +alias org.eolang.int.mod | ||
| +alias org.eolang.int.lt | ||
| +alias org.eolang.int.gt | ||
| +alias org.eolang.int.eq | ||
| +alias org.eolang.float.add | ||
| +alias org.eolang.float.sub | ||
| +alias org.eolang.float.mul | ||
| +alias org.eolang.float.div | ||
| +alias org.eolang.float.lt | ||
| +alias org.eolang.float.gt | ||
| +alias org.eolang.float.eq | ||
| +alias org.eolang.float.isnan | ||
| +alias org.eolang.float.isinf | ||
| +spdx SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com | ||
| +spdx SPDX-License-Identifier: MIT | ||
|
|
||
| # Formats a string using a template and arguments | ||
| [format args] > sprintf | ||
| [] > formatted | ||
| memory > i-mem | ||
| memory > arg-index-mem | ||
| memory > result-mem | ||
|
|
||
| [] > processor | ||
| seq > @ | ||
| # Initialize | ||
| 0 > idx | ||
| i-mem.put idx | ||
| 0 > arg-idx | ||
| arg-index-mem.put arg-idx | ||
| "" > res | ||
| result-mem.put res | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| format.length > len | ||
|
|
||
| # Parse format string character by character | ||
| while (lt (i-mem.get) len) | ||
| seq | ||
| format.at (i-mem.get) > ch | ||
|
|
||
| # Check for format specifier | ||
| if. | ||
| and | ||
| eq ch "%" | ||
| lt (add (i-mem.get) 1) len | ||
| seq | ||
| # Get next character | ||
| i-mem.put (add (i-mem.get) 1) | ||
| format.at (i-mem.get) > next-ch | ||
|
|
||
| # Handle different specifiers | ||
| if. | ||
| eq next-ch "%" | ||
| # Escaped % | ||
| seq | ||
| result-mem.put (concat (result-mem.get) "%") | ||
| i-mem.put (add (i-mem.get) 1) | ||
| if. | ||
| eq next-ch "s" | ||
| # String | ||
| seq | ||
| if. | ||
| lt (arg-index-mem.get) args.length | ||
| seq | ||
| args.at (arg-index-mem.get) > arg | ||
| result-mem.put (concat (result-mem.get) (string arg)) | ||
| arg-index-mem.put (add (arg-index-mem.get) 1) | ||
| # Missing argument | ||
| result-mem.put (concat (result-mem.get) "%s") | ||
| i-mem.put (add (i-mem.get) 1) | ||
| if. | ||
| or (eq next-ch "d") (eq next-ch "i") | ||
| # Integer | ||
| seq | ||
| if. | ||
| lt (arg-index-mem.get) args.length | ||
| seq | ||
| args.at (arg-index-mem.get) > arg | ||
| [] > int-to-str | ||
| # Simple integer to string conversion | ||
| if. | ||
| lt arg 0 | ||
| seq | ||
| "-" > sign | ||
| mul arg -1 > n | ||
| seq | ||
| "" > sign | ||
| arg > n | ||
| if. | ||
| eq n 0 | ||
| "0" | ||
| seq | ||
| "" > digits | ||
| while (gt n 0) | ||
| seq | ||
| mod n 10 > digit | ||
| div n 10 > n | ||
| if. | ||
| eq digit 0 | ||
| digits.write "0" | ||
| if. | ||
| eq digit 1 | ||
| digits.write "1" | ||
| if. | ||
| eq digit 2 | ||
| digits.write "2" | ||
| if. | ||
| eq digit 3 | ||
| digits.write "3" | ||
| if. | ||
| eq digit 4 | ||
| digits.write "4" | ||
| if. | ||
| eq digit 5 | ||
| digits.write "5" | ||
| if. | ||
| eq digit 6 | ||
| digits.write "6" | ||
| if. | ||
| eq digit 7 | ||
| digits.write "7" | ||
| if. | ||
| eq digit 8 | ||
| digits.write "8" | ||
| digits.write "9" | ||
| concat sign digits | ||
| > int-str | ||
MrEx3cut0r marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| result-mem.put (concat (result-mem.get) int-str) | ||
| arg-index-mem.put (add (arg-index-mem.get) 1) | ||
| # Missing argument | ||
| result-mem.put (concat (result-mem.get) "%d") | ||
| i-mem.put (add (i-mem.get) 1) | ||
| if. | ||
| or (eq next-ch "f") (eq next-ch "F") | ||
| # Float | ||
| seq | ||
| if. | ||
| lt (arg-index-mem.get) args.length | ||
| seq | ||
| args.at (arg-index-mem.get) > arg | ||
| # Simple float formatting | ||
| string arg > float-str | ||
| result-mem.put (concat (result-mem.get) float-str) | ||
| arg-index-mem.put (add (arg-index-mem.get) 1) | ||
| # Missing argument | ||
| result-mem.put (concat (result-mem.get) "%f") | ||
| i-mem.put (add (i-mem.get) 1) | ||
| # Unknown specifier - keep as is | ||
| seq | ||
| result-mem.put (concat (result-mem.get) "%") | ||
| result-mem.put (concat (result-mem.get) next-ch) | ||
| i-mem.put (add (i-mem.get) 1) | ||
| # Regular character | ||
| seq | ||
| result-mem.put (concat (result-mem.get) ch) | ||
| i-mem.put (add (i-mem.get) 1) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| result-mem.get | ||
|
|
||
| processor > @ | ||
|
|
||
| formatted > @ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.