#!/bin/bash
# 2009-2010 Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain


# TODO: see etersoft-build-utils/tests/test_isnumber.sh
isnumber()
{
	echo "$*" | estrlist filter_strip_spaces | grep -q "^[0-9]\+$"
}

# the same like estrlist match (reg_has)
# Note: used egrep! write '[0-9]+(first|two)', not '[0-9]\+...'
rhas()
{
	echo "$1" | egrep -q -- "$2"
}


# drop listed options
# FIXME: do not handle args like -Uh, only -U -h separately
# "-n -u -r -i" n i -> "-u -r"
drop_args()
{
    local ARGS="$1"
    shift
    local LISTIGNORE="$@"
    echo "$ARGS" | sed -e "s|-[${LISTIGNORE/ /}]||g" | estrlist filter_strip_spaces
    #echo "$ARGS" | \
    #    ( for i in $LISTIGNORE ; do sed -e "s|-$i||g" ;  done ) #| sed -e "s| +| |g"
}

initial_letter()
{
    echo "$1" | head -c1
}

skip_initial_letter()
{
    echo "$1" | cut -c2-
}


is_dirpath()
{
    [ "$1" = "." ] && return
    rhas "$1" "/"
}

is_absolute_path()
{
    rhas "$1" "^/"
}
