Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
Update strToIntList for LF line endings
Browse files Browse the repository at this point in the history
Updated strToIntList description
  • Loading branch information
Patrick Cox authored Jan 22, 2019
1 parent 3a1b38f commit bbb8752
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/fileReader.sml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ end;
(* Parse a string into a : int list by the delimiter " "
returns : int list
As found at https://stackoverflow.com/questions/14750444/how-can-i-parse-string-to-int-int-tuple-in-sml/35730421 *)
As found at https://stackoverflow.com/questions/14750444/how-can-i-parse-string-to-int-int-tuple-in-sml/35730421
Note that mapPartial discards anything that can't be converted to an integer (when Int.fromString return None.
and that it is assumed the string always contains \n as the last two characters are removed by taking the substring. *)
fun strToIntList str =
let
val str' = String.substring(str, 0, size str-2)
val str' = String.substring(str, 0, size str-1)
in
List.mapPartial Int.fromString (String.tokens (fn c => c = #" ") str')
end;
Expand All @@ -48,8 +50,8 @@ fun strListToIntListList(stringList : string list) =

(* THE FOLLOWING IS NOT USED *)
(* Trim last n characters of a string
returns : string
fun trimString (str : string, n_chars : int) =
returns : string *)
(* fun trimString (str : string, n_chars : int) =
String.substring(str, 0, size str - n_chars);
Apply trimString on each element of a : string list
Expand Down

0 comments on commit bbb8752

Please sign in to comment.