Check if the given string conforms to the rules described
in "<a href="http://tools.ietf.org/html/rfc2616#section-2.2"
>2.2 Basic Rules</a>" of <a href="http://tools.ietf.org/html/rfc2616"
>RFC 2616</a>.
14242
public static boolean isValid(String token)
    {
        if (token == null || token.length() == 0)
        {
            return false;
        }

        int len = token.length();

        for (int i = 0; i < len; ++i)
        {
            if (isSeparator(token.charAt(i)))
            {
                return false;
            }
        }

        return true;
    }
1194274
function( string ) {
    var negated, matches, patterns = this.patterns, i = patterns.length;
    while ( i-- ) {
      negated = patterns[ i ].negated;
      matches = patterns[ i ].matcher( string );
      if ( negated !== matches ) {
        return matches;
      }
    }
    return false;
  }
578898
function _rule_check($rule, $str) {
        if (($rule['flag'] & PSCWS4_ZRULE_INCLUDE) && !$this->_rule_checkbit($str, $rule['bit']))
            return false;
        if (($rule['flag'] & PSCWS4_ZRULE_EXCLUDE) && $this->_rule_checkbit($str, $rule['bit']))
            return false;
        return true;
    }
2896
function applyRules(_string, _ruleSet, _skip) {

      if(_skip.indexOf(_string.toLowerCase()) === -1) {
        var i = 0, rule;
        while(rule = _ruleSet[i++]) {
          if(_string.match(rule[0])) {
            return _string.replace(rule[0], rule[1]);
          }
        }
      }

      return _string;
    }
351258
def matches_rule(message, rule, destinations = None) :
    ""
    if not isinstance(message, Message) :
        raise TypeError("message must be a Message")
    #end if
    rule = unformat_rule(rule)
    eavesdrop = rule.get("eavesdrop", "false") == "true"

    def match_message_type(expect, actual) :
        return \
            actual == Message.type_from_string(expect)
    #end match_message_type

    def match_path_namespace(expect, actual) :
        return \
            (
                actual != None
            and
                (
                    expect == actual
                or
                    actual.startswith(expect) and (expect == "/" or actual[len(expect)] == "/")
                )
            )
    #end match_path_namespace

    def match_dotted_namespace(expect, actual) :
        return \
            (
                actual != None
            and
                (
                    expect == actual
                or
                    actual.startswith(expect) and actual[len(expect)] == "."
                )
            )
    #end match_dotted_namespace

    def get_nth_arg(msg, n, expect_types) :
        msg_signature = parse_signature(msg.signature)
        if n >= len(msg_signature) :
            raise IndexError("arg nr %d beyond nr args %d" % (n, len(msg_signature)))
        #end if
        val = msg.all_objects[n]
        valtype = msg_signature[n]
        if valtype not in expect_types :
            if False :
                raise TypeError \
                  (
                        "expecting one of types %s, not %s for arg %d val %s"
                    %
                        ((repr(expect_types), repr(valtype), n, repr(val)))
                  )
            #end if
            val = None # never match
        #end if
        return \
            val
    #end get_nth_arg

    def get_arg_0_str(message) :
        return \
            get_nth_arg(message, 0, [BasicType(TYPE.STRING)])
    #end get_arg_0_str

    def match_arg_paths(expect, actual) :
        return \
            (
                actual != None
            and
                (
                    expect == actual
                or
                    expect.endswith("/") and actual.startswith(expect)
                or
                    actual.endswith("/") and expect.startswith(actual)
                )
            )
    #end match_arg_paths

    match_types = \
        ( # note that message attribute value of None will fail to match
          # any expected string value, which is exactly what we want
            ("type", None, match_message_type, None),
            ("sender", None, operator.eq, None),
            ("interface", None, operator.eq, None),
            ("member", None, operator.eq, None),
            ("path", None, operator.eq, None),
            ("destination", None, operator.eq, None),
            ("path_namespace", "path", match_path_namespace, None),
            ("arg0namespace", None, match_dotted_namespace, get_arg_0_str),
            # “arg«n»path” handled specially below
        )

#begin matches_rule
    keys_used = set(rule.keys()) - {"eavesdrop"}
    matches = \
        (
            eavesdrop
        or
            destinations == None
        or
            message.destination == None
        or
            message.destination in destinations
        )
    if matches :
        try_matching = iter(match_types)
        while True :
            try_rule = next(try_matching, None)
            if try_rule == None :
                break
            rulekey, attrname, action, accessor = try_rule
            if attrname == None :
                attrname = rulekey
            #end if
            if rulekey in rule :
                if accessor != None :
                    val = accessor(message)
                else :
                    val = getattr(message, attrname)
                #end if
                keys_used.remove(rulekey)
                if not action(rule[rulekey], val) :
                    matches = False
                    break
                #end if
            #end if
        #end while
    #end if
    if matches :
        try_matching = iter(rule.keys())
        while True :
            try_key = next(try_matching, None)
            if try_key == None :
                break
            if try_key.startswith("arg") and not try_key.endswith("namespace") :
                argnr = try_key[3:]
                is_path = argnr.endswith("path")
                if is_path :
                    argnr = argnr[:-4]
                #end if
                argnr = int(argnr)
                if not (0 <= argnr < 64) :
                    raise ValueError("argnr %d out of range" % argnr)
                #end if
                argval = get_nth_arg \
                  (
                    message,
                    argnr,
                    [BasicType(TYPE.STRING)] + ([], [BasicType(TYPE.OBJECT_PATH)])[is_path]
                  )
                keys_used.remove(try_key)
                if not (operator.eq, match_arg_paths)[is_path](rule[try_key], argval) :
                    matches = False
                    break
                #end if
            #end if
        #end while
    #end if
    if matches and len(keys_used) != 0 :
        # fixme: not checking for unrecognized rule keys if I didn’t try matching them all
        raise KeyError("unrecognized rule keywords: %s" % ", ".join(sorted(keys_used)))
    #end if
    return \
        matches
767308
function isValidSha(str) {
  if (typeof str === 'string' && str.length === 40) {
    const res = str.match(/[0-9a-f]/g);
    return res && res.length === 40;
  }
  return false;
}
442590
def validate_url(url):
    

    scheme = url.split('://')[0].lower()
    if scheme not in url_schemes:
        return False
    if not bool(url_regex.search(url)):
        return False
    return True
72306
private static boolean matchRuleRegex(String regex, String value) {

        if (value == null) {
            value = "";
        }

        if (regex == null) {
            return true;
        }
        if ((regex.length() > 0) && (regex.charAt(0) == '!')) {
            return !value.matches(regex.substring(1));
        } else {
            return value.matches(regex);
        }
    }
953330
def is_valid_regex(regex):
    """"""
    if len(regex) == 0:
        return False
    try:
        re.compile(regex)
        return True
    except sre_constants.error:
        return False
488934
def check_path_matches_patterns(path, patterns):
    '''  '''
    path = os.path.abspath(path)
    for patt in patterns:
        if isinstance(patt, six.string_types):
            if path == patt:
                return True
        elif patt.search(path):
            return True
    return False
96498
def check_convert_string(obj, name=None,
                             no_leading_trailing_whitespace=True,
                             no_whitespace=False,
                             no_newline=True,
                             whole_word=False,
                             min_len=1,
                             max_len=0):
        """"""
        if not name:
            name = 'Argument'
        obj = ensure_unicode(obj, name=name)
        if no_whitespace:
            if _PATTERN_WHITESPACE.match(obj):
                raise ValueError('%s cannot contain whitespace' % name)
        elif no_leading_trailing_whitespace and _PATTERN_LEAD_TRAIL_WHITESPACE.match(obj):
            raise ValueError('%s contains leading/trailing whitespace' % name)
        if (min_len and len(obj) < min_len) or (max_len and len(obj) > max_len):
            raise ValueError('%s too short/long (%d/%d)' % (name, min_len, max_len))
        if whole_word:
            if not _PATTERN_WORD.match(obj):
                raise ValueError('%s can only contain alphanumeric (unicode) characters, numbers and the underscore'
                                 % name)
        # whole words cannot contain newline so additional check not required
        elif no_newline and '\n' in obj:
            raise ValueError('%s cannot contain line breaks' % name)
        return obj
1160924
private boolean isMatchingString(String value1, String value2) {
        
        boolean valuesMatch = true;
        
        if (value1 == null) {
            if (value2 != null) {
                valuesMatch = false;
            }
        } else { 
            valuesMatch = value1.equals(value2);
        }
        
        return valuesMatch;
    }
701671
function _match (rule, cmtData) {
        var path = rule.subject.split('.');
        var extracted = cmtData;
        while (path.length > 0) {
            var item = path.shift();
            if (item === '') {
                continue;
            }
            if (extracted.hasOwnProperty(item)) {
                extracted = extracted[item];
            }
            if (extracted === null || typeof extracted === 'undefined') {
                extracted = null;
                break;
            }
        }
        if (extracted === null) {
            // Null precondition implies anything
            return true;
        }
        switch (rule.op) {
            case '<':
                return extracted < rule.value;
            case '>':
                return extracted > rule.value;
            case '~':
            case 'regexp':
                return (new RegExp(rule.value)).test(extracted.toString());
            case '=':
            case 'eq':
                return rule.value ===
                    ((typeof extracted === 'number') ?
                        extracted : extracted.toString());
            case '!':
            case 'not':
                return !_match(rule.value, extracted);
            case '&&':
            case 'and':
                if (Array.isArray(rule.value)) {
                    return rule.value.every(function (r) {
                        return _match(r, extracted);
                    });
                } else {
                    return false;
                }
            case '||':
            case 'or':
                if (Array.isArray(rule.value)) {
                    return rule.value.some(function (r) {
                        return _match(r, extracted);
                    });
                } else {
                    return false;
                }
            default:
                return false;
        }
    }
1033548
def is_likely_link(text):
    '''
    '''
    text = text.lower()

    # Check for absolute or relative URLs
    if (
        text.startswith('http://')
        or text.startswith('https://')
        or text.startswith('ftp://')
        or text.startswith('/')
        or text.startswith('//')
        or text.endswith('/')
        or text.startswith('../')
    ):
        return True

    # Check if it has a alphanumeric file extension and not a decimal number
    dummy, dot, file_extension = text.rpartition('.')

    if dot and file_extension and len(file_extension) <= 4:
        file_extension_set = frozenset(file_extension)

        if file_extension_set \
           and file_extension_set <= ALPHANUMERIC_CHARS \
           and not file_extension_set <= NUMERIC_CHARS:
            if file_extension in COMMON_TLD:
                return False

            file_type = mimetypes.guess_type(text, strict=False)[0]

            if file_type:
                return True
            else:
                return False
924685
private static boolean isValidBrace(String url) {
        if (null == url || url.trim().length() == 0) {
            return false;
        }

        boolean isInsideVariable = false;
        StringTokenizer tokenizer = new StringTokenizer(url, "{}", true);
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            if (token.equals("{")) {
                // { is not allowed inside of a variable specification
                if (isInsideVariable) {
                    return false;
                }
                isInsideVariable = true;
            } else if (token.equals("}")) {
                // } must be preceded by {;
                if (!isInsideVariable) {
                    return false;
                }
                isInsideVariable = false;
            }
        }
        return true;
    }
453352
def is_valid_url(url):
    
    regex = re.compile(
            r'^(?:http|ftp)s?://' # http:// or https://
            r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
            #r'localhost|' #localhost...
            r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
            r'(?::\d+)?' # optional port
            r'(?:/?|[/?]\S+)$', re.IGNORECASE)
    return bool(regex.match(url))
75704
function isBinaryString( str ) {
	var len,
		ch,
		i;
	if ( !isString( str ) ) {
		return false;
	}
	len = str.length;
	if ( !len ) {
		return false;
	}
	for ( i = 0; i < len; i++ ) {
		ch = str[ i ];
		if ( ch !== '1' && ch !== '0' ) {
			return false;
		}
	}
	return true;
}