XRootD
Loading...
Searching...
No Matches
XrdOucTokenizer.cc
Go to the documentation of this file.
1
/******************************************************************************/
2
/* */
3
/* X r d O u c T o k e n i z e r . c c */
4
/* */
5
/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6
/* Produced by Andrew Hanushevsky for Stanford University under contract */
7
/* DE-AC02-76-SFO0515 with the Deprtment of Energy */
8
/* */
9
/* This file is part of the XRootD software suite. */
10
/* */
11
/* XRootD is free software: you can redistribute it and/or modify it under */
12
/* the terms of the GNU Lesser General Public License as published by the */
13
/* Free Software Foundation, either version 3 of the License, or (at your */
14
/* option) any later version. */
15
/* */
16
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19
/* License for more details. */
20
/* */
21
/* You should have received a copy of the GNU Lesser General Public License */
22
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24
/* */
25
/* The copyright holder's institutional names and contributor's names may not */
26
/* be used to endorse or promote products derived from this software without */
27
/* specific prior written permission of the institution or contributor. */
28
/******************************************************************************/
29
30
#ifndef WIN32
31
#include <unistd.h>
32
#endif
33
#include <ctype.h>
34
#include <stdlib.h>
35
#include <string.h>
36
37
#include "
XrdOuc/XrdOucTokenizer.hh
"
38
39
/******************************************************************************/
40
/* A t t a c h */
41
/******************************************************************************/
42
43
void
XrdOucTokenizer::Attach
(
char
*bp)
44
{
45
buff = bp;
46
token = 0;
47
tnext = (
char
*)
""
;
48
notabs = 0;
49
}
50
51
/******************************************************************************/
52
/* G e t L i n e */
53
/******************************************************************************/
54
55
char
*
XrdOucTokenizer::GetLine
()
56
{
57
char
*bp;
58
59
// Check if end of buffer has been reached.
60
//
61
if
(!buff || *buff ==
'\0'
)
return
(
char
*)NULL;
62
63
// Find the next record in the buffer
64
//
65
bp = buff;
66
if
(notabs)
67
while
(*bp && (*bp ==
' '
|| *bp ==
'\t'
)) bp++;
68
else
while
(*bp && *bp ==
' '
) bp++;
69
70
tnext = bp;
71
72
// Find the end of the record
73
//
74
if
(notabs)
75
while
(*bp && *bp !=
'\n'
) {
if
(*bp ==
'\t'
) *bp =
' '
; bp++;}
76
else
while
(*bp && *bp !=
'\n'
) bp++;
77
78
// Set the end of the line
79
//
80
if
(*bp) {*bp =
'\0'
; buff = bp+1;}
81
else
buff = bp;
82
83
// All done
84
//
85
token = 0;
86
return
tnext;
87
}
88
89
/******************************************************************************/
90
/* G e t T o k e n */
91
/******************************************************************************/
92
93
char
*
XrdOucTokenizer::GetToken
(
char
**rest,
int
lowcase)
94
{
95
96
// Skip to the first non-blank character.
97
//
98
while
(*tnext && *tnext ==
' '
) tnext++;
99
if
(!*tnext)
return
(
char
*)NULL;
100
token = tnext;
101
102
// Find the end of the token.
103
//
104
if
(lowcase)
while
(*tnext && *tnext !=
' '
)
105
{*tnext = (char)tolower((
int
)*tnext); tnext++;}
106
else
while
(*tnext && *tnext !=
' '
) {tnext++;}
107
if
(*tnext) {*tnext =
'\0'
; tnext++;}
108
109
// Check if remaining line is to be returned
110
//
111
if
(rest)
112
{
while
(*tnext && *tnext ==
' '
) tnext++;
113
*rest = tnext;
114
}
115
116
// All done here.
117
//
118
return
token;
119
}
120
121
/******************************************************************************/
122
/* R e t T o k e n */
123
/******************************************************************************/
124
125
void
XrdOucTokenizer::RetToken
()
126
{
127
// Backup one token, we can only back up once
128
//
129
if
(token)
130
{
if
(*tnext) token[strlen(token)] =
' '
;
131
tnext = token;
132
token = 0;
133
}
134
}
XrdOucTokenizer.hh
XrdOucTokenizer::GetToken
char * GetToken(char **rest=0, int lowcase=0)
Definition
XrdOucTokenizer.cc:93
XrdOucTokenizer::GetLine
char * GetLine()
Definition
XrdOucTokenizer.cc:55
XrdOucTokenizer::Attach
void Attach(char *bp)
Definition
XrdOucTokenizer.cc:43
XrdOucTokenizer::RetToken
void RetToken()
Definition
XrdOucTokenizer.cc:125
XrdOuc
XrdOucTokenizer.cc
Generated by
1.10.0