Skip to content

Commit

Permalink
Merge pull request #10 from skilesare/main
Browse files Browse the repository at this point in the history
removing asserts
  • Loading branch information
skilesare committed May 13, 2022
2 parents 1017009 + 21bd3ce commit 5cbdf88
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/conversion.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1135,16 +1135,22 @@ module {
};

//conversts "10" to 10
public func textToNat( txt : Text) : Nat {
assert(txt.size() > 0);
let chars = txt.chars();
var num : Nat = 0;
for (v in chars){
let charToNum = Nat32.toNat(Char.toNat32(v)-48);
assert(charToNum >= 0 and charToNum <= 9);
num := num * 10 + charToNum;
public func textToNat( txt : Text) : ?Nat {
if(txt.size() > 0){
let chars = txt.chars();
var num : Nat = 0;
for (v in chars){
let charToNum = Nat32.toNat(Char.toNat32(v)-48);
if(charToNum >= 0 and charToNum <= 9){
num := num * 10 + charToNum;
} else {
return null;
};
};
?num;
}else {
return null;
};
num;
};

public func propertyToText(a:Types.Property):Text{valueToText(a.value)};
Expand Down

0 comments on commit 5cbdf88

Please sign in to comment.