Skip to content

Commit

Permalink
Merge pull request #9 from skilesare/main
Browse files Browse the repository at this point in the history
change Text to nat
  • Loading branch information
skilesare committed May 13, 2022
2 parents 936bdd4 + 3921e79 commit 1017009
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/conversion.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,17 @@ module {
return textToByteBuffer(_text).toArray();
};

//encodes a string it to a giant int
public func encodeTextAsNat(phrase : Text) : ?Nat {
var theSum : Nat = 0;
Iter.iterate(Text.toIter(phrase), func (x : Char, n : Nat){
//todo: check for digits
theSum := theSum + ((Nat32.toNat(Char.toNat32(x)) - 48) * 10 ** (phrase.size()-n-1));
});
return ?theSum;
};

//conversts "10" to 10
public func textToNat( txt : Text) : Nat {
assert(txt.size() > 0);
let chars = txt.chars();
Expand Down

0 comments on commit 1017009

Please sign in to comment.