Skip to content
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

Iteration 24 #660

Merged
merged 3 commits into from
May 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
adding missing file
  • Loading branch information
arakov committed May 31, 2024
commit 18be93a8f3bcd847ec6939060a7674cfeb36aa41
74 changes: 74 additions & 0 deletions src60/extensions/formatter.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import system'text;

singleton helper
{
readIndex(string s, ref int i, ref int retVal)
{
char ch := $0;
int n := 0;
int v := 0;

ch := s[i];

while (ch != $125)
{
n := intConvertor.convert(ch);
if(n >= 30h && n <= 39h)
{
n := n - 30h;

v := v * 10;
v := v + n
}
else
{
InvalidArgumentException.raise()
};

i := i + 1;
ch := s[i];
};

retVal := v
}
}

public extension stringFormatterOp : String
{
interpolate(params object[] args)
{
auto buffer := new TextBuilder();

int len := self.Length;
int i := 0;
char ch := $0;
int chlen := 0;
int index := 0;

while (i < len)
{
ch := self[i];

if (ch == $123)
{
i := i + 1;

helper.readIndex(self, ref i, ref index);

var arg := args[index];
buffer.write(arg.toString());

chlen := 1
}
else
{
buffer.write(ch);
chlen := ch.Length;
};

i := i + chlen
};

^ *buffer;
}
}
Loading