Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/include
File: pcre_scanner.h
// Copyright (c) 2005, Google Inc.
[0] Fix | Delete
// All rights reserved.
[1] Fix | Delete
//
[2] Fix | Delete
// Redistribution and use in source and binary forms, with or without
[3] Fix | Delete
// modification, are permitted provided that the following conditions are
[4] Fix | Delete
// met:
[5] Fix | Delete
//
[6] Fix | Delete
// * Redistributions of source code must retain the above copyright
[7] Fix | Delete
// notice, this list of conditions and the following disclaimer.
[8] Fix | Delete
// * Redistributions in binary form must reproduce the above
[9] Fix | Delete
// copyright notice, this list of conditions and the following disclaimer
[10] Fix | Delete
// in the documentation and/or other materials provided with the
[11] Fix | Delete
// distribution.
[12] Fix | Delete
// * Neither the name of Google Inc. nor the names of its
[13] Fix | Delete
// contributors may be used to endorse or promote products derived from
[14] Fix | Delete
// this software without specific prior written permission.
[15] Fix | Delete
//
[16] Fix | Delete
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
[17] Fix | Delete
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
[18] Fix | Delete
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
[19] Fix | Delete
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
[20] Fix | Delete
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
[21] Fix | Delete
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
[22] Fix | Delete
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
[23] Fix | Delete
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[24] Fix | Delete
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
[25] Fix | Delete
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
[26] Fix | Delete
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[27] Fix | Delete
//
[28] Fix | Delete
// Author: Sanjay Ghemawat
[29] Fix | Delete
//
[30] Fix | Delete
// Regular-expression based scanner for parsing an input stream.
[31] Fix | Delete
//
[32] Fix | Delete
// Example 1: parse a sequence of "var = number" entries from input:
[33] Fix | Delete
//
[34] Fix | Delete
// Scanner scanner(input);
[35] Fix | Delete
// string var;
[36] Fix | Delete
// int number;
[37] Fix | Delete
// scanner.SetSkipExpression("\\s+"); // Skip any white space we encounter
[38] Fix | Delete
// while (scanner.Consume("(\\w+) = (\\d+)", &var, &number)) {
[39] Fix | Delete
// ...;
[40] Fix | Delete
// }
[41] Fix | Delete
[42] Fix | Delete
#ifndef _PCRE_SCANNER_H
[43] Fix | Delete
#define _PCRE_SCANNER_H
[44] Fix | Delete
[45] Fix | Delete
#include <assert.h>
[46] Fix | Delete
#include <string>
[47] Fix | Delete
#include <vector>
[48] Fix | Delete
[49] Fix | Delete
#include <pcrecpp.h>
[50] Fix | Delete
#include <pcre_stringpiece.h>
[51] Fix | Delete
[52] Fix | Delete
namespace pcrecpp {
[53] Fix | Delete
[54] Fix | Delete
class PCRECPP_EXP_DEFN Scanner {
[55] Fix | Delete
public:
[56] Fix | Delete
Scanner();
[57] Fix | Delete
explicit Scanner(const std::string& input);
[58] Fix | Delete
~Scanner();
[59] Fix | Delete
[60] Fix | Delete
// Return current line number. The returned line-number is
[61] Fix | Delete
// one-based. I.e. it returns 1 + the number of consumed newlines.
[62] Fix | Delete
//
[63] Fix | Delete
// Note: this method may be slow. It may take time proportional to
[64] Fix | Delete
// the size of the input.
[65] Fix | Delete
int LineNumber() const;
[66] Fix | Delete
[67] Fix | Delete
// Return the byte-offset that the scanner is looking in the
[68] Fix | Delete
// input data;
[69] Fix | Delete
int Offset() const;
[70] Fix | Delete
[71] Fix | Delete
// Return true iff the start of the remaining input matches "re"
[72] Fix | Delete
bool LookingAt(const RE& re) const;
[73] Fix | Delete
[74] Fix | Delete
// Return true iff all of the following are true
[75] Fix | Delete
// a. the start of the remaining input matches "re",
[76] Fix | Delete
// b. if any arguments are supplied, matched sub-patterns can be
[77] Fix | Delete
// parsed and stored into the arguments.
[78] Fix | Delete
// If it returns true, it skips over the matched input and any
[79] Fix | Delete
// following input that matches the "skip" regular expression.
[80] Fix | Delete
bool Consume(const RE& re,
[81] Fix | Delete
const Arg& arg0 = RE::no_arg,
[82] Fix | Delete
const Arg& arg1 = RE::no_arg,
[83] Fix | Delete
const Arg& arg2 = RE::no_arg
[84] Fix | Delete
// TODO: Allow more arguments?
[85] Fix | Delete
);
[86] Fix | Delete
[87] Fix | Delete
// Set the "skip" regular expression. If after consuming some data,
[88] Fix | Delete
// a prefix of the input matches this RE, it is automatically
[89] Fix | Delete
// skipped. For example, a programming language scanner would use
[90] Fix | Delete
// a skip RE that matches white space and comments.
[91] Fix | Delete
//
[92] Fix | Delete
// scanner.SetSkipExpression("\\s+|//.*|/[*](.|\n)*?[*]/");
[93] Fix | Delete
//
[94] Fix | Delete
// Skipping repeats as long as it succeeds. We used to let people do
[95] Fix | Delete
// this by writing "(...)*" in the regular expression, but that added
[96] Fix | Delete
// up to lots of recursive calls within the pcre library, so now we
[97] Fix | Delete
// control repetition explicitly via the function call API.
[98] Fix | Delete
//
[99] Fix | Delete
// You can pass NULL for "re" if you do not want any data to be skipped.
[100] Fix | Delete
void Skip(const char* re); // DEPRECATED; does *not* repeat
[101] Fix | Delete
void SetSkipExpression(const char* re);
[102] Fix | Delete
[103] Fix | Delete
// Temporarily pause "skip"ing. This
[104] Fix | Delete
// Skip("Foo"); code ; DisableSkip(); code; EnableSkip()
[105] Fix | Delete
// is similar to
[106] Fix | Delete
// Skip("Foo"); code ; Skip(NULL); code ; Skip("Foo");
[107] Fix | Delete
// but avoids creating/deleting new RE objects.
[108] Fix | Delete
void DisableSkip();
[109] Fix | Delete
[110] Fix | Delete
// Reenable previously paused skipping. Any prefix of the input
[111] Fix | Delete
// that matches the skip pattern is immediately dropped.
[112] Fix | Delete
void EnableSkip();
[113] Fix | Delete
[114] Fix | Delete
/***** Special wrappers around SetSkip() for some common idioms *****/
[115] Fix | Delete
[116] Fix | Delete
// Arranges to skip whitespace, C comments, C++ comments.
[117] Fix | Delete
// The overall RE is a disjunction of the following REs:
[118] Fix | Delete
// \\s whitespace
[119] Fix | Delete
// //.*\n C++ comment
[120] Fix | Delete
// /[*](.|\n)*?[*]/ C comment (x*? means minimal repetitions of x)
[121] Fix | Delete
// We get repetition via the semantics of SetSkipExpression, not by using *
[122] Fix | Delete
void SkipCXXComments() {
[123] Fix | Delete
SetSkipExpression("\\s|//.*\n|/[*](?:\n|.)*?[*]/");
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
void set_save_comments(bool comments) {
[127] Fix | Delete
save_comments_ = comments;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
bool save_comments() {
[131] Fix | Delete
return save_comments_;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
// Append to vector ranges the comments found in the
[135] Fix | Delete
// byte range [start,end] (inclusive) of the input data.
[136] Fix | Delete
// Only comments that were extracted entirely within that
[137] Fix | Delete
// range are returned: no range splitting of atomically-extracted
[138] Fix | Delete
// comments is performed.
[139] Fix | Delete
void GetComments(int start, int end, std::vector<StringPiece> *ranges);
[140] Fix | Delete
[141] Fix | Delete
// Append to vector ranges the comments added
[142] Fix | Delete
// since the last time this was called. This
[143] Fix | Delete
// functionality is provided for efficiency when
[144] Fix | Delete
// interleaving scanning with parsing.
[145] Fix | Delete
void GetNextComments(std::vector<StringPiece> *ranges);
[146] Fix | Delete
[147] Fix | Delete
private:
[148] Fix | Delete
std::string data_; // All the input data
[149] Fix | Delete
StringPiece input_; // Unprocessed input
[150] Fix | Delete
RE* skip_; // If non-NULL, RE for skipping input
[151] Fix | Delete
bool should_skip_; // If true, use skip_
[152] Fix | Delete
bool skip_repeat_; // If true, repeat skip_ as long as it works
[153] Fix | Delete
bool save_comments_; // If true, aggregate the skip expression
[154] Fix | Delete
[155] Fix | Delete
// the skipped comments
[156] Fix | Delete
// TODO: later consider requiring that the StringPieces be added
[157] Fix | Delete
// in order by their start position
[158] Fix | Delete
std::vector<StringPiece> *comments_;
[159] Fix | Delete
[160] Fix | Delete
// the offset into comments_ that has been returned by GetNextComments
[161] Fix | Delete
int comments_offset_;
[162] Fix | Delete
[163] Fix | Delete
// helper function to consume *skip_ and honour
[164] Fix | Delete
// save_comments_
[165] Fix | Delete
void ConsumeSkip();
[166] Fix | Delete
};
[167] Fix | Delete
[168] Fix | Delete
} // namespace pcrecpp
[169] Fix | Delete
[170] Fix | Delete
#endif /* _PCRE_SCANNER_H */
[171] Fix | Delete
[172] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function