Scan

Section: Misc. Reference Manual Pages (3C++)
Updated: C++ String Library
Index Return to Main Contents
 

NAME

StringScan - a class for scanning through strings  

SYNOPSIS


# include <String.h>
   ...
  class StringScan {
    public:
        enum ScanType { ByField,ByMatch };
        StringScan(String &s, ScanType t, const StringSearch &s_s);
        int operator()(String &match);
        int cursor();
    private:
        String   *str;
        const StringSearch *ss;
        ScanType   st;
        StringRange pos;
        char       lf;
};
   ...
 

DESCRIPTION

The StringScan class is used to scan through a given String. There are two ways to scan through a String, ByField and ByMatch.

ByField scans through a String using the given field as a seperator. In this respect it is like the split funtion.


ByMatch scans through a String and returns successive matches using the specified StringSearch function.

The String being scanned should not be changed during the scan. If the String is to be changed, then Scan should be passed a copy of the String.  

EXAMPLES


  String s1("This is a test"); String w;

StringScan Word(s1,StringScan::ByMatch,RXnonwhite); Word(w); Assert(w=="This"); Word(w); Assert(w=="is"); Word(w); Assert(w=="a"); Word(w); Assert(w=="test");

String s2("schemers:*:271:79:Roland Schemers:/u/schemers:/bin/csh");

StringScan next_field(s2,StringScan::ByField,String(":")); String pf;

next_field(pf); Assert(pf=="schemers"); next_field(pf); Assert(pf=="*"); next_field(pf); Assert(pf=="271"); next_field(pf); Assert(pf=="79"); next_field(pf); Assert(pf=="Roland Schemers"); next_field(pf); Assert(pf=="/u/schemers"); next_field(pf); Assert(pf=="/bin/csh");

s2="one 1 two 2 three3four 4 negative five -5"; StringScan next_num(s2,StringScan::ByMatch,RXint); String num;

next_num(num); Assert(num=="1"); next_num(num); Assert(num=="2"); next_num(num); Assert(num=="3"); next_num(num); Assert(num=="4"); next_num(num); Assert(num=="-5");


 

Index

NAME
SYNOPSIS
DESCRIPTION
EXAMPLES

This document was created by man2html, using the manual pages.
Time: 20:33:51 GMT, July 24, 2024