YAP 7.1.0
Line Manipulation Utilities

This package provides a set of useful predicates to manipulate sequences of characters codes, usually first read in as a line. More...

Detailed Description

This package provides a set of useful predicates to manipulate sequences of characters codes, usually first read in as a line.

It is available by loading the

:- use_module(library(lineutils)).
use_module( +Files )

Class Documentation

◆ search_for/2

class search_for/2

search_for(+ Char,+ Line)

Search for a character Char in the list of codes Line

◆ scan_integer/3

class scan_integer/3

scan_integer(? Int,+ Line,+ RestOfLine)

Scan the list of codes Line for an integer Nat, either a positive, zero, or negative integer, and unify RestOfLine with the remainder of the line

◆ integer/3

class integer/3

integer(? Int,+ Line,+ RestOfLine)

Scan the list of codes Line for an integer Nat, either a positive, zero, or negative integer, and unify RestOfLine with the remainder of the line

◆ scan_natural/3

class scan_natural/3

scan_natural(? Nat,+ Line,+ RestOfLine)

Scan the list of codes Line for a natural number Nat, zero or a positive integer, and unify RestOfLine with the remainder of the line

◆ natural/3

class natural/3

natural(? Nat,+ Line,+ RestOfLine)

Scan the list of codes Line for a natural number Nat, zero or a positive integer, and unify RestOfLine with the remainder of the line

◆ skip_whitespace/2

class skip_whitespace/2

skip_whitespace(+ Line,+ RestOfLine)

Scan the list of codes Line for white space, namely for tabbing and space characters

◆ blank/2

class blank/2

blank(+ Line,+ RestOfLine)

The list of codes Line is formed by white space, namely by tabbing and space characters

◆ split/2

class split/2

split(+ Line,- Split)

Unify Words with a set of strings obtained from Line by using the blank characters as separators

◆ split/3

class split/3

split(+ Line,+ Separators,- Split)

Unify Words with a set of strings obtained from Line by using the character codes in Separators as separators As an example, consider:

?- split("Hello * I am free"," *",S).
S = ["Hello","I","am","free"] ?
split(+ Line,+ Separators,- Split)

◆ split_unquoted/3

class split_unquoted/3

split_unquoted(+ Line,+ Separators,- Split)

Unify Words with a set of strings obtained from Line by using the character codes in Separators as separators, but treat text wi thin double quotes as a single unit As an example, consider:

?- split("Hello * I \"am free\""," *",S).
S = ["Hello","I","am free"] ?

◆ split_quoted/5

class split_quoted/5

split_quoted(+ Line,+ Separators, GroupQuotes, SingleQuotes, - Split)

Unify Words with a set of strings obtained from Line by using the character codes in Separators as separators, but treat text within quotes as a single unit As an example, consider:

?- split_quoted("Hello * I \"am free\""," *",S).
S = ["Hello","I","am free"] ?

◆ fields/2

class fields/2

fields(+ Line,- Split)

Unify Words with a set of strings obtained from Line by using the blank characters as field separators

◆ fields/3

class fields/3

fields(+ Line,+ Separators,- Split)

Unify Words with a set of strings obtained from Line by using the character codes in Separators as separators for fields If two separators occur in a row, the field is considered empty As an example, consider:

?- fields("Hello I am free"," *",S).
S = ["Hello","","I","am","","free"] ?
fields(+ Line,+ Separators,- Split)

◆ glue/3

class glue/3

glue(+ Words,+ Separator,- Line)

Unify Line with string obtained by glueing Words with the character code Separator

◆ copy_line/2

class copy_line/2

copy_line(+ StreamInput,+ StreamOutput)

Copy a line from StreamInput to StreamOutput

◆ filter/3

class filter/3

filter(+ StreamInp, + StreamOut, + Goal)

For every line LineIn in stream StreamInp, execute call(Goal,LineIn,LineOut), and output LineOut to stream StreamOut If call(Goal,LineIn,LineOut) fails, nothing will be output but execution continues with the next line As an example, consider a procedure to select the second and fifth field of a CSV table :

select(Sep, In, Out) :-
fields(In, Sep, [_,F2,_,_,F5|_]),
fields(Out,Sep, [F2,F5]).
fields :-
select(? Element, ? List, ? Residue)

◆ process/2

class process/2

process(+ StreamInp, + Goal)

For every line LineIn in stream StreamInp, call call(Goal,LineIn)

meta

For every line LineIn in stream StreamInp, call call(Goal,LineIn)

◆ file_filter/3

class file_filter/3

file_filter(+ FileIn, + FileOut, + Goal)

meta

  • Parameters
    <em>FileIn</em>File to process
    <em>FileOut</em>Output file, often user_error
    <em>Goal</em>to be metacalled, receives FileIn and FileOut as extra arguments
  • Returns
    succeeds

    For every line LineIn in file FileIn, execute call(Goal,LineIn,LineOut), and output LineOut to file FileOut

    The input stream is accessible through the alias filter_input, and the output stream is accessible through filter_output

◆ file_filter_with_initialization/5

class file_filter_with_initialization/5

file_filter_with_initialization(+ FileIn, + FileOut, + Goal, + FormatCommand, + Arguments)

Same as file_filter/3 , but before starting the filter execute format/3 on the output stream, using FormatCommand and Arguments

◆ file_filter_with_start_end/5

class file_filter_with_start_end/5

file_filter_with_start_end(+ FileIn, + FileOut, + Goal, + StartGoal, + EndGoal)

Same as file_filter/3 , but before starting the filter execute StartGoal, and call ENdGoal as an epilog

The input stream are always accessible through filter_output and filter_input

◆ file_select/2

class file_select/2

file_select(+ FileIn, + Goal)

meta

  • Parameters
    <em>FileIn</em>File or Stream to process
    <em>Goal</em>to be metacalled, receives FileIn as extra arguments
  • Returns
    bindings to arguments of Goal
  • For every line LineIn in file FileIn, execute call(Goal,LineIn)`
  • The input stream is accessible through the alias filter_input, and the output stream is accessible through filter_output