Define a symbol in the lexicon, e.g. "J_NUMBER"
@param string internal name which will be defined as a php constant
@param string optional alternative human-readable name
@return int value of defined constant
432070
function define( $c, $alt = '' ){
		if( ! is_string($c) ){
			trigger_error("symbol $c must be a string", E_USER_WARNING );
			return null;
		}
		if( defined($c) ){
			trigger_error("Conflict on symbol $c, already defined", E_USER_ERROR );
		}
		define( $c, ++ $this->i );
		$this->names[ $this->i ] = $alt ? $alt : $c;
		return $this->i;
	}
249590
public static function ord(string $char): int
    {
        $h = \ord($char[0]);
        
        if ($h <= 0x7F) {
            return $h;
        }
        
        if ($h < 0xC2) {
            throw new \InvalidArgumentException('Could not get unicode codepoint for character: "' . $char . '"');
        }
        
        if ($h <= 0xDF) {
            return ($h & 0x1F) << 6 | (\ord($char[1]) & 0x3F);
        }
        
        if ($h <= 0xEF) {
            return (($h & 0x0F) << 12 | (\ord($char[1]) & 0x3F) << 6 | (\ord($char[2]) & 0x3F));
        }
        
        if ($h <= 0xF4) {
            return (($h & 0x0F) << 18 | (\ord($char[1]) & 0x3F) << 12 | (\ord($char[2]) & 0x3F) << 6 | (\ord($char[3]) & 0x3F));
        }
        
        throw new \InvalidArgumentException('Could not get unicode codepoint for character: "' . $char . '"');
    }
1340382
public function get_option_name_from_constant($constant) {
        if (is_null(self::$constants)) {
            $constants = get_defined_constants(true);
            $constants = isset($constants['curl']) ? $constants['curl'] : array();
            $constants = array_flip($constants);
            self::$constants = $constants;
        }
        if (isset(self::$constants[$constant])) {
            return self::$constants[$constant];
        }
        throw new coding_exception('Unknown curl constant value: ' . $constant);
    }
567153
private function strConst($number) {
        static $lookup;
        if (!$lookup) {
            $lookup = array();
            $r = new ReflectionClass('HTML5_TreeBuilder');
            $consts = $r->getConstants();
            foreach ($consts as $const => $num) {
                if (!is_int($num)) continue;
                $lookup[$num] = $const;
            }
        }
        return $lookup[$number];
    }
433848
function name( $i ){
		if( is_int($i) ){
			if( ! isset($this->names[$i]) ){
				trigger_error("symbol ".var_export($i,1)." is unknown in ".get_class($this), E_USER_NOTICE );
				return 'UNKNOWN';
			}
			else {
				return $this->names[$i];
			}
		}
		else if ( ! isset($this->literals[$i]) ){
			trigger_error("literal symbol ".var_export($i,1)." is unknown in ".get_class($this), E_USER_NOTICE );
		}
		return $i;
	}
698091
public function staticArrayLength($name)
    {
        $nestedTypes = $this->nestedTypes($name);

        if ($nestedTypes === false) {
            return 1;
        }
        $match = [];

        if (preg_match('/[0-9]{1,}/', $nestedTypes[count($nestedTypes) - 1], $match) === 1) {
            return (int) $match[0];
        }
        return 1;
    }
681268
public Symbol resolveIdent(String name) {
        if (name.equals(""))
            return syms.errSymbol;
        JavaFileObject prev = log.useSource(null);
        try {
            JCExpression tree = null;
            for (String s : name.split("\\.", -1)) {
                if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
                    return syms.errSymbol;
                tree = (tree == null) ? make.Ident(names.fromString(s))
                                      : make.Select(tree, names.fromString(s));
            }
            JCCompilationUnit toplevel =
                make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
            toplevel.packge = syms.unnamedPackage;
            return attr.attribIdent(tree, toplevel);
        } finally {
            log.useSource(prev);
        }
    }
1207557
public function setName($name)
    {
        if (in_array($name, MathEnumeration::asArray())) {
            $this->name = $name;
        } else {
            $msg = "${name} is not a valid QTI Math constant.";
            throw new InvalidArgumentException($msg);
        }
    }
729164
public int getInt(String name)
  {
    Integer value = (Integer) get(name);

    if (value != null)
      return value.intValue();
    else
      return 0;
  }
30149
public static function referInt($name, $default = null)
    {
        $res = self::getReferParams($name);
        if (!is_null($res)) return self::parseInputToInt($res);
        return (is_null($default) ? null : intval($default));
    }
431124
public static function SC($name)
    {
        // name consists of a single letter
        if (!preg_match("/^[A-Z]+$/i", $name)) {
            throw new \RuntimeException("invalid column name '$name'");
        }

        // solve longer names recursively
        if (preg_match("/^([A-Z])([A-Z]+)$/i", $name, $matches)) {
            return pow(26, strlen($matches[2])) * (self::SC($matches[1]) + 1) + self::SC($matches[2]);
        }

        return ord(strtoupper($name)) - 64 - 1;
    }
697632
public function get(string $name): Constant
    {
        if (!$this->has($name)) {
            $constant = new Constant($name, null);
            parent::add($constant);

            return $constant;
        }

        return parent::get($name);
    }
151722
public function unit_to_constant($name)
    {
        $camel = '';
        $name = str_replace(':', '', $name);
        foreach (explode('_', $name) as $str) {
            $camel .= ucfirst($str);
        }
        return 'PHPWarrior\Units\\' . $camel;
    }
1155589
private function parseReferences($name): string
    {
        if (preg_match_all('/\$\{(.*[a-z\.0-9])\}/si', $name, $results, PREG_SET_ORDER)) {
            foreach ($results as $match) {
                $replace = $match[0];
                $key = $match[1];

                // Handle using relative placement like get('db.${.default}.host');
                if (strpos($key, '.') === 0) {
                    // using relative placement
                    $key = substr($name, 0, strpos($name, $replace) - 1) . $key;
                }

                // get the value
                $value = $this->get($key);
                if ($value === null || $value === '' || $value === false) {
                    throw new InvalidArgumentException(
                        $key . ' replacement for ' . $name . ' must not be null or empty'
                    );
                }

                $name = str_replace($replace, $value, $name);
            }
        }

        return $name;
    }
1209330
private static function parseTableName($name)
    {
        // Init buffer
        $buffer = '';
        $strOpen = false;
        $names = array();

        $strLen = strlen($name);
        for($i = 0; $i < $strLen; $i++)
        {
            if($name[$i] == '"')
            {
                // Toggle strings
                if( !$strOpen || ($strOpen && $name[$i - 1] != "\\") )
                {
                    $strOpen = !$strOpen;
                }
            }
            elseif($name[$i] == '.' && !$strOpen)
            {
                // Save and cleanup buffer. Continue.
                $names[] = $buffer;
                $buffer = '';
                continue;
            }

            // Store char
            $buffer .= $name[$i];
        }

        // Save last buffer
        if($buffer != '') {
            $names[] = $buffer;
        }

        return $names;
    }
122596
private function getAttributeIndex(string $name): ?int
    {
        $index = $this->ruleMainIndexes[$name] ?? null;

        return $index;
    }
1093272
protected function phpJsonEncodeNameValue( $name, $value )
    {
        return (sprintf("%s:%s", $this->phpJsonEncode(strval($name)), $this->phpJsonEncode($value)));
    }