# Path: hq/hquery/evaluation_error.py
# class HqueryEvaluationError(RuntimeError):
# 
#     @classmethod
#     def must_be_node_set(cls, obj):
#         if not is_node_set(obj):
#             raise HqueryEvaluationError('Expected a node set, but found a(n) {0}'.format(obj.__class__.__name__))
# 
#     @classmethod
#     def must_be_node_set_or_sequence(cls, obj):
#         if not (is_node_set(obj) or is_sequence(obj)):
#             raise HqueryEvaluationError('Expected a node set or sequence, but found a(n) {0}'.format(
#                 obj.__class__.__name__
#             ))
# 
# Path: hq/hquery/expression_context.py
# def get_context_node():
#     return peek_context().node
# 
# Path: hq/hquery/functions/core_boolean.py
# class boolean:
# 
#     def __init__(self, obj):
#         if is_node_set(obj):
#             self.value = len(obj) > 0
#         elif is_number(obj):
#             f = float(obj)
#             self.value = bool(f) and not isnan(f)
#         else:
#             self.value = bool(obj)
# 
#     def __bool__(self):
#         return self.value
# 
#     def __nonzero__(self):
#         return self.__bool__()
# 
#     def __str__(self):
#         return str(self.value).lower()
# 
#     def __eq__(self, other):
#         return is_boolean(other) and self.value == other.value
# 
#     def __repr__(self):
#         return 'boolean({0})'.format(self.value)
# 
# Path: hq/hquery/object_type.py
# def string_value(obj):
#     if is_tag_node(obj) or is_attribute_node(obj) or is_text_node(obj):
#         return derive_text_from_node(obj, peek_context().preserve_space)
#     elif is_number(obj) or is_boolean(obj):
#         return str(obj)
#     elif is_node_set(obj):
#         return string_value(obj[0]) if len(obj) > 0 else ''
#     elif is_sequence(obj):
#         return ''.join(string_value(item) for item in obj)
#     elif is_string(obj):
#         return obj
#     else:
#         raise NotImplementedError('string_value not implemented for type "{0}"'.format(obj.__class__.__name__))


import re
from hq.hquery.evaluation_error import HqueryEvaluationError
from hq.hquery.expression_context import get_context_node
from hq.hquery.functions.core_boolean import boolean
from hq.hquery.object_type import string_value


exports = ('lower_case', 'matches', 'replace', 'string_join', 'tokenize', 'upper_case')


def lower_case(value):
    return string_value(value).lower()


def matches(*args):
    scenario = len(args)
    flags = 0

    if scenario < 1 or scenario > 3:

# Path: hq/hquery/evaluation_error.py
# class HqueryEvaluationError(RuntimeError):
# 
#     @classmethod
#     def must_be_node_set(cls, obj):
#         if not is_node_set(obj):
#             raise HqueryEvaluationError('Expected a node set, but found a(n) {0}'.format(obj.__class__.__name__))
# 
#     @classmethod
#     def must_be_node_set_or_sequence(cls, obj):
#         if not (is_node_set(obj) or is_sequence(obj)):
#             raise HqueryEvaluationError('Expected a node set or sequence, but found a(n) {0}'.format(
#                 obj.__class__.__name__
#             ))
# 
# Path: hq/hquery/expression_context.py
# def get_context_node():
#     return peek_context().node
# 
# Path: hq/hquery/functions/core_boolean.py
# class boolean:
# 
#     def __init__(self, obj):
#         if is_node_set(obj):
#             self.value = len(obj) > 0
#         elif is_number(obj):
#             f = float(obj)
#             self.value = bool(f) and not isnan(f)
#         else:
#             self.value = bool(obj)
# 
#     def __bool__(self):
#         return self.value
# 
#     def __nonzero__(self):
#         return self.__bool__()
# 
#     def __str__(self):
#         return str(self.value).lower()
# 
#     def __eq__(self, other):
#         return is_boolean(other) and self.value == other.value
# 
#     def __repr__(self):
#         return 'boolean({0})'.format(self.value)
# 
# Path: hq/hquery/object_type.py
# def string_value(obj):
#     if is_tag_node(obj) or is_attribute_node(obj) or is_text_node(obj):
#         return derive_text_from_node(obj, peek_context().preserve_space)
#     elif is_number(obj) or is_boolean(obj):
#         return str(obj)
#     elif is_node_set(obj):
#         return string_value(obj[0]) if len(obj) > 0 else ''
#     elif is_sequence(obj):
#         return ''.join(string_value(item) for item in obj)
#     elif is_string(obj):
#         return obj
#     else:
#         raise NotImplementedError('string_value not implemented for type "{0}"'.format(obj.__class__.__name__))


# Path: hq/hquery/functions/extend_string.py
import re
from hq.hquery.evaluation_error import HqueryEvaluationError
from hq.hquery.expression_context import get_context_node
from hq.hquery.functions.core_boolean import boolean
from hq.hquery.object_type import string_value



exports = ('lower_case', 'matches', 'replace', 'string_join', 'tokenize', 'upper_case')


def lower_case(value):
    return string_value(value).lower()


def matches(*args):
    scenario = len(args)
    flags = 0

    if scenario < 1 or scenario > 3:

        raise HqueryEvaluationError('matches() called with {0} arguments; expected one, two or three.'.format(scenario))