Page Speed Optimization Libraries
1.13.35.1
|
#include "html_detector.h"
Public Member Functions | |
bool | ConsiderInput (const StringPiece &data) |
bool | already_decided () const |
bool | probable_html () const |
Precondition: already_decided() true (or ConsiderInput returning true). | |
void | ReleaseBuffered (GoogleString *out_buffer) |
void | ForceDecision (bool is_html) |
This class tries to heuristically detect whether something that claims to HTML is likely to be. For now, it merely looks at whether the first non-whitespace/non-BOM character is <.
Typical usage: HtmlDetector detect_html_;
if (!detect_html_.already_decided() && detect_html_.ConsiderInput(data)) { GoogleString buffered; detect_html_.ReleaseBuffered(&buffered); if (detect_html_.probable_html()) { do html-specific bits with buffered } else { do non-html things with buffered } }
if (detect_html_.already_decided()) { do appropriate things with data based on detect_html_.probable_html() }
|
inline |
Returns true if we have seen enough input to make a guess as to whether it's HTML or not.
bool net_instaweb::HtmlDetector::ConsiderInput | ( | const StringPiece & | data | ) |
Processes the data, trying to determine if it's HTML or not. If there is enough evidence to make a decision, returns true.
If true is returned, already_decided() will be true as well, and hence probable_html() will be accessible. buffered() will not be changed.
If false is returned, data will be accumulated inside buffered().
Precondition: !already_decided()
void net_instaweb::HtmlDetector::ForceDecision | ( | bool | is_html | ) |
Forces already_decided() to true, and probable_html() to match is_html.
Precondition: !already_decided()
void net_instaweb::HtmlDetector::ReleaseBuffered | ( | GoogleString * | out_buffer | ) |
Transfers any data that was buffered by ConsiderInput calls that returned false into *out_buffer. The old value of out_buffer is overwritten, and HtmlDetector's internal buffers are cleared.