Path: blob/trunk/third_party/closure/goog/dom/pattern/text.js
2868 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview DOM pattern to match a text node.16*17* @author [email protected] (Robby Walker)18*/1920goog.provide('goog.dom.pattern.Text');2122goog.require('goog.dom.NodeType');23goog.require('goog.dom.pattern');24goog.require('goog.dom.pattern.AbstractPattern');25goog.require('goog.dom.pattern.MatchType');26272829/**30* Pattern object that matches text by exact matching or regular expressions.31*32* @param {string|RegExp} match String or regular expression to match against.33* @constructor34* @extends {goog.dom.pattern.AbstractPattern}35* @final36*/37goog.dom.pattern.Text = function(match) {38/**39* The text or regular expression to match.40*41* @private {string|RegExp}42*/43this.match_ = match;44};45goog.inherits(goog.dom.pattern.Text, goog.dom.pattern.AbstractPattern);464748/**49* Test whether the given token is a text token which matches the string or50* regular expression provided in the constructor.51*52* @param {Node} token Token to match against.53* @param {goog.dom.TagWalkType} type The type of token.54* @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern55* matches, <code>NO_MATCH</code> otherwise.56* @override57*/58goog.dom.pattern.Text.prototype.matchToken = function(token, type) {59if (token.nodeType == goog.dom.NodeType.TEXT &&60goog.dom.pattern.matchStringOrRegex(this.match_, token.nodeValue)) {61this.matchedNode = token;62return goog.dom.pattern.MatchType.MATCH;63}6465return goog.dom.pattern.MatchType.NO_MATCH;66};676869