Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
findmark.h
Go to the documentation of this file.
1#ifndef FINDMARK_H
2#define FINDMARK_H
3/*
4The functions of this family are for finding wanted sequenses of simbols
5in strings or input streams. Such functions are often needed
6at treating of any data for finding right
7position from which some meaningful data begin at stream.
8
9Copyright (c) 2000 I. B. Smirnov
10
11Permission to use, copy, modify, distribute and sell this file for any purpose
12is hereby granted without fee, provided that the above copyright notice,
13this permission notice, and notices about any modifications of the original
14text appear in all copies and in supporting documentation.
15The file is provided "as is" without express or implied warranty.
16*/
17
18#include "wcpplib/util/String.h"
20
21// The function findmark finds string s in stream file
22// and returns 1 at current position at the next symbol.
23// Finding no string it returns 0.
24int findmark(std::istream& file, const char* s);
25
26// Returns the same, also finds the length of string, the index of its
27// beginning and the index of the next symbol after string.
28// Indexes are count from current position in stream at which the function
29// was called.
30// Previously this function was findmark_uca from unsigned char alternative.
31// Note that dispite of T the internally this class is working with char.
32// The string ws is copied to string char before the work.
33// T is any class with index operation.
34template <class T>
35int findmark_a(std::istream& file, T ws, long qws,
36 // DynLinArr< T > ws, long qws,
37 long& nbeg, long& nnext);
38
39// The same but returns also the previous symbol or '\0' for the string
40// at the beginning of the stream.
41// T is any class with index operation.
42template <class T>
43int findmark_b(std::istream& file, T ws, long qws,
44 // DynLinArr< T > ws, long qws,
45 long& nbeg, long& nnext, char& prev);
46
47template <class T>
48int findmark_a(std::istream& file, T ws, long qws,
49 // DynLinArr< T > ws, long qws,
50 long& nbeg, long& nnext) {
51 mfunname("int findmark_a(...)");
52 check_econd11(qws, < 1, mcerr);
53 //check_econd12(qws , > , ws.get_qel() , mcerr);
54
55 nbeg = 0;
56 nnext = 0;
57
58 char* s = new char[qws + 1];
59 long n;
60 for (n = 0; n < qws; n++) {
61 s[n] = ws[n];
62 }
63 s[qws] = '\0';
64 int ic;
65
66 char* fs = new char[qws + 1];
67 for (n = 0; n < qws; n++) {
68 if (file.eof() == 1) {
69 delete[] fs;
70 delete[] s;
71 return 0;
72 } else {
73 ic = file.get();
74 fs[n] = ic;
75 }
76 }
77 // if ((ic = file.get()) == EOF) {delete fs; return 0;}
78 // else fs[n] = ic;
79 fs[qws] = '\0';
80 nnext = qws;
81
82 while (strcmp(fs, s) != 0) {
83 for (n = 1; n < qws; n++)
84 fs[n - 1] = fs[n];
85 if (file.eof() == 1) {
86 delete[] fs;
87 delete[] s;
88 return 0;
89 } else {
90 ic = file.get();
91 }
92 //if((ic=file.get())==EOF) { delete fs; return 0; }
93 fs[qws - 1] = ic;
94 //fs[qws]='\0';
95 nbeg++;
96 nnext++;
97 //cout<<fs<<'\n';
98 }
99 delete[] fs;
100 delete[] s;
101 return 1;
102}
103
104template <class T>
105int findmark_b(std::istream& file, T ws, long qws,
106 // DynLinArr< T > ws, long qws,
107 long& nbeg, long& nnext, char& prev) {
108 mfunname("int findmark_b(...)");
109 check_econd11(qws, < 1, mcerr);
110 //check_econd12(qws , > , ws.get_qel() , mcerr);
111
112 nbeg = 0;
113 nnext = 0;
114 //char c;
115 prev = '\0';
116
117 char* s = new char[qws + 1];
118 long n;
119 for (n = 0; n < qws; n++) {
120 s[n] = ws[n];
121 }
122 s[qws] = '\0';
123 int ic;
124 //int l=strlen(s); // length does not include end symbol
125 //cout<<"l="<<l<<'\n';
126
127 char* fs = new char[qws + 1];
128 for (n = 0; n < qws; n++) {
129 if (file.eof() == 1) {
130 //mcout<<"eof at:\n";
131 //Iprintn(mcout, n);
132 delete[] fs;
133 delete[] s;
134 return 0;
135 } else {
136 ic = file.get();
137 fs[n] = ic;
138 }
139 }
140 // if ((ic = file.get()) == EOF) {delete fs; return 0;}
141 // else fs[n] = ic;
142 fs[qws] = '\0';
143 nnext = qws;
144
145 while (strcmp(fs, s) != 0) {
146 prev = fs[0];
147 for (n = 1; n < qws; n++)
148 fs[n - 1] = fs[n];
149 if (file.eof() == 1) {
150 //mcout<<"eof at:\n";
151 //Iprint2n(mcout, nbeg, nnext);
152 delete[] fs;
153 delete[] s;
154 return 0;
155 } else {
156 ic = file.get();
157 }
158 //if((ic=file.get())==EOF) { delete fs; return 0; }
159 fs[qws - 1] = ic;
160 //fs[qws]='\0';
161 nbeg++;
162 nnext++;
163 }
164 //mcout<<"mark found\n";
165 delete[] fs;
166 delete[] s;
167 return 1;
168}
169
170// I don't remember what this function in doing
171int findmark_other_repeat(std::istream& file, std::ostream& outfile,
172 const char* s);
173
174// returns -1 or index of found word
175
176// The following two functions find any of given strings, the first met.
177// They return the number of string met ( in the interval 0 -- q-1).
178// If none of strings found, they return -1.
179int find1ofnmark(std::istream& file, int q, // number of strings
180 char* s[]); // addresses
181int find1ofnmark(std::istream& file, int q, // number of strings
182 const String str[]); // addresses
183
184#endif
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#define mfunname(string)
Definition: FunNameStack.h:67
std::string String
Definition: String.h:75
int findmark_other_repeat(std::istream &file, std::ostream &outfile, const char *s)
Definition: findmark.cpp:46
int findmark_b(std::istream &file, T ws, long qws, long &nbeg, long &nnext, char &prev)
Definition: findmark.h:105
int findmark(std::istream &file, const char *s)
Definition: findmark.cpp:18
int findmark_a(std::istream &file, T ws, long qws, long &nbeg, long &nnext)
Definition: findmark.h:48
int find1ofnmark(std::istream &file, int q, char *s[])
Definition: findmark.cpp:89
#define mcerr
Definition: prstream.h:135