line utilities

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2052 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2008-01-14 16:34:06 +00:00
parent d7eaa84d9e
commit 535a43245d

36
library/lineutils.yap Normal file
View File

@ -0,0 +1,36 @@
:- module(line_utils,
[search_for/3,
scan_natural/3,
split/3
]).
:- use_module(library(lists),
[member/2]).
search_for(C) --> [C], !.
search_for(C) --> [_],
search_for(C).
scan_natural(N) -->
scan_natural(0, N).
scan_natural(N0,N) -->
[C],
{C >= 0'0, C =< 0'9 }, !,
{ N1 is N0*10+(C-0'0) },
get_natural(N1,N).
scan_natural(N,N) --> [].
split(String, SplitCodes, [S|Strings]) :-
split(SplitCodes, S, Strings, String, []).
split(SplitCodes, [], [New|Set]) -->
[C],
{ member(C, SplitCodes) }, !,
split(SplitCodes, New, Set).
split(SplitCodes, [C|New], Set) -->
[C], !,
split(SplitCodes, New, Set).
split(_, [], []) --> [].