private function parseStringToIntervals( $string )
    {

        if( !$length = mb_strlen( $string ) ) {
            return array();
        }

        // The following isn't as bat shit crazy loco nutjob wtf loony as it looks.
        // People need to enter literal commas, dashes and backslashes and you can't easily write a regex for this because the escape sequences can become, well arbritraily complex.
        // Imagine the following
        //      200-300 => array( 200, 300 ); great
        //      \\200-300 => array( \200, 300 ); fine, you can do a regex for that
        //      200\\\-300 => array( 200\-300 ); but not easily for this or something more insane-o
        // Unfortunately php's str_csv functions fails us here with a enclosure delimiter as the empty string ''. This means the DELIMTER (or INTERVAL_SEPARATOR) isn't escaped properly.

        // The following works fine for non-multibyte char separators and is very quick.
        $intervals = array();
        $interval = array('');
        $c = 0;

        $isCharEscaped = false;

        for( $i = 0; $i < $length; $i++ ) {

            $char = mb_substr( $string, $i, 1 );

            if( $isCharEscaped ) {

                if( $char === self::NULL_CHARACTER ) {
                    if( $interval[$c] === '') {
                        $interval[$c] = null;
                    }
                } else {
                    $interval[$c] .= $char;
                }

                $isCharEscaped = false;

            } else {

                switch( $char ) {
                    case self::ESCAPE_CHARACTER;
                        $isCharEscaped = true;
                        break;
                    case self::RANGE_SEPARATOR;
                        $interval[++$c] = '';
                        break;
                    case self::INTERVAL_SEPARATOR;
                        if( $interval = $this->prepInterval( $interval ) ) {
                            $intervals[] = $interval;
                        }
                        $interval = array('');
                        $c = 0;
                        break;
                    default:
                        $interval[$c] .= $char;
                        break;

                }

            }

        }

        if( $interval = $this->prepInterval( $interval ) ) {
            $intervals[] = $interval;
        }

        return $intervals;

    }
private function parseStringToIntervals( $string )
    {

        if( !$length = mb_strlen( $string ) ) {
            return array();
        }

        // The following isn't as bat shit crazy loco nutjob wtf loony as it looks.
        // People need to enter literal commas, dashes and backslashes and you can't easily write a regex for this because the escape sequences can become, well arbritraily complex.
        // Imagine the following
        //      200-300 => array( 200, 300 ); great
        //      \\200-300 => array( \200, 300 ); fine, you can do a regex for that
        //      200\\\-300 => array( 200\-300 ); but not easily for this or something more insane-o
        // Unfortunately php's str_csv functions fails us here with a enclosure delimiter as the empty string ''. This means the DELIMTER (or INTERVAL_SEPARATOR) isn't escaped properly.

        // The following works fine for non-multibyte char separators and is very quick.
        $intervals = array();
        $interval = array('');
        $c = 0;

        $isCharEscaped = false;

        for( $i = 0; $i < $length; $i++ ) {

            $char = mb_substr( $string, $i, 1 );

            if( $isCharEscaped ) {

                if( $char === self::NULL_CHARACTER ) {
                    if( $interval[$c] === '') {
                        $interval[$c] = null;
                    }
                } else {
                    $interval[$c] .= $char;
                }

                $isCharEscaped = false;

            } else {

                switch( $char ) {
                    case self::ESCAPE_CHARACTER;
                        $isCharEscaped = true;
                        break;
                    case self::RANGE_SEPARATOR;
                        $interval[++$c] = '';
                        break;
                    case self::INTERVAL_SEPARATOR;
                        if( $interval = $this->prepInterval( $interval ) ) {
                            $intervals[] = $interval;
                        }
                        $interval = array('');
                        $c = 0;
                        break;
                    default:
                        $interval[$c] .= $char;
                        break;

                }

            }

        }

        if( $interval = $this->prepInterval( $interval ) ) {
            $intervals[] = $interval;
        }

        return $intervals;

    }
private function parseStringToIntervals ( $ string ) { if ( ! $ length = mb_strlen ( $ string ) ) { return array ( ) ; } // The following isn't as bat shit crazy loco nutjob wtf loony as it looks. // People need to enter literal commas, dashes and backslashes and you can't easily write a regex for this because the escape sequences can become, well arbritraily complex. // Imagine the following //      200-300 => array( 200, 300 ); great //      \\200-300 => array( \200, 300 ); fine, you can do a regex for that //      200\\\-300 => array( 200\-300 ); but not easily for this or something more insane-o // Unfortunately php's str_csv functions fails us here with a enclosure delimiter as the empty string ''. This means the DELIMTER (or INTERVAL_SEPARATOR) isn't escaped properly. // The following works fine for non-multibyte char separators and is very quick. $ intervals = array ( ) ; $ interval = array ( '' ) ; $ c = 0 ; $ isCharEscaped = false ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ char = mb_substr ( $ string , $ i , 1 ) ; if ( $ isCharEscaped ) { if ( $ char === self :: NULL_CHARACTER ) { if ( $ interval [ $ c ] === '' ) { $ interval [ $ c ] = null ; } } else { $ interval [ $ c ] .= $ char ; } $ isCharEscaped = false ; } else { switch ( $ char ) { case self :: ESCAPE_CHARACTER ; $ isCharEscaped = true ; break ; case self :: RANGE_SEPARATOR ; $ interval [ ++ $ c ] = '' ; break ; case self :: INTERVAL_SEPARATOR ; if ( $ interval = $ this -> prepInterval ( $ interval ) ) { $ intervals [ ] = $ interval ; } $ interval = array ( '' ) ; $ c = 0 ; break ; default : $ interval [ $ c ] .= $ char ; break ; } } } if ( $ interval = $ this -> prepInterval ( $ interval ) ) { $ intervals [ ] = $ interval ; } return $ intervals ; }
Parse the data into an array of unique values
@param string $string String represensation of a set which we're going to parse into
a valid, sorted array of intervals
@return array
Parse the data into an array of unique values