@param string $fullName
@param int    $characterLimit
@param array  $characters

@return array
970669
private function doGenerate($fullName, $characterLimit, array $characters = array())
    {
        $balineseGenerator = new BalinesePetrukUsername();
        if (-1 !== $balineseGenerator->isReservedName($fullName)) {
            $characters = array_merge($characters, $balineseGenerator->generate($fullName, $characterLimit));
        }

        $islamicGenerator = new IslamicPetrukUsername();
        if (-1 !== $islamicGenerator->isReservedName($fullName)) {
            $characters = array_merge($characters, $islamicGenerator->generate($fullName, $characterLimit));
        }

        $westernGenerator = new WesternPetrukUsername();
        if (-1 !== $westernGenerator->isReservedName($fullName)) {
            $characters = array_merge($characters, $westernGenerator->generate($fullName, $characterLimit));
        }

        $genericGenerator = new GenericPetrukUsername();
        $characters = array_merge($characters, $genericGenerator->generate($fullName, $characterLimit));

        return $characters;
    }
647125
public static function convertFromBinary($string, $characters) {
        if ($string === '' || empty($characters)) {
            return '';
        }
        $string   = str_split($string);
        $callback = function($str) {
                return ord($str);
            };
        $string    = array_map($callback, $string);
        $converted = static::baseConvert($string, 256, strlen($characters));
        $callback  = function ($num) use ($characters) {
                return $characters[$num];
            };
        $ret = implode('', array_map($callback, $converted));
        return $ret;
    }
1281901
private boolean doesMatchFullName(String firstName, String fullName){
        boolean matching = false;
        if(firstName != null && !firstName.isEmpty() && fullName != null && !fullName.isEmpty()){
            String firstFromCMDB;
            String[] array = fullName.split(" ");

            firstName = firstName.toLowerCase();
            firstFromCMDB = array[0];
            firstFromCMDB = firstFromCMDB.toLowerCase();
            if(firstFromCMDB.length() < firstName.length()){
                if(firstName.indexOf(firstFromCMDB) != -1){
                    matching = true;
                }
            }else if (firstFromCMDB.indexOf(firstName) != -1){
                matching = true;
            }
        }
        return matching;
    }
109905
public final String getFullString(final int pos, final int len, String charsetName) {
        if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
                                                                             + (pos < 0 ? pos : (pos + len)));

        try {
            return new String(buffer, origin + pos, len, charsetName);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
        }
    }
747745
public static function explode($string, $characters = ";>|/\\<")
    {
        $string = self::sanitizeString($string);

        if ($string === null) {
            return [];
        }

        // Convert characters into a safe regular expression
        $splitRegex = "";
        for ($i = 0; $i < strlen($characters); $i++) {
            $splitRegex .= "\\" . $characters[$i];
        }
        $splitRegex = "/[" . $splitRegex . "]/";

        $rawElements = preg_split($splitRegex, $string);
        $elements = [];
        foreach($rawElements as $rawElement) {
            $element = self::sanitizeString($rawElement);

            if ($element !== null) {
                $elements[] = $element;
            }
        }

        return $elements;
    }
1202674
private function parseFullClassName($fullName)
    {
        $parts = explode("\\", $fullName);
        $name = array_pop($parts);
        $namespace = implode("\\", $parts);
        return [$name, $namespace];
    }
746916
private static function executeStep6($characters) {
        $bars = '';
        for ($i = 0; $i < 65; $i++) {
            $barPosition = self::$barPositions[$i];
            $descender = $barPosition[0];
            $ascender = $barPosition[1];
            $extenderDescender = !!($characters[$descender[0]] & (1 << $descender[1]));
            $extenderAscender = !!($characters[$ascender[0]] & (1 << $ascender[1]));

            if ($extenderDescender && $extenderAscender) {
                $bars .= 'F';
            } elseif ($extenderDescender) {
                $bars .= 'D';
            } elseif ($extenderAscender) {
                $bars .= 'A';
            } else {
                $bars .= 'T';
            }
        }

        return $bars;
    }
236580
public final String getFullString(final int len, String charsetName) {
        if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
                                                                                + (position + len - origin));

        try {
            String string = new String(buffer, position, len, charsetName);
            position += len;
            return string;
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
        }
    }
774010
public static function codePointAt($chars, int $index, int $limit = null): int
    {
        if (\is_array($chars) === false && ($chars instanceof CharSequence) === false) {
            throw new InvalidArgumentException('Only char arrays and sequences can be processed!');
        }

        // Validate char array
        if (\is_array($chars)) {
            $test = reset($chars);

            if ($test === false || ($test instanceof static) === false) {
                throw new InvalidArgumentException('Array must contain char elements!');
            }
        }

        // Validate specified index
        if ($index < 0) {
            throw new InvalidArgumentException('Index cannot be negative!');
        }

        // Validate length
        if ($limit !== null) {
            if ($limit < 0 || $index >= $limit) {
                throw new InvalidArgumentException('Limit cannot be negative and index must be lower than specified limit!');
            }

            $length = \is_array($chars) ? count($chars) : $chars->length();

            if ($limit > $length) {
                throw new InvalidArgumentException('Limit cannot be greater than char array/sequence!');
            }
        }

        $char       = \is_array($chars) ? $chars[$index] : $chars->charAt($index);
        $stringChar = (string) $char;

        return mb_ord($stringChar, mb_detect_encoding($stringChar));
    }
627227
public function getAllCharacterNewestMail(int $limit = 10): Collection
    {

        $user = auth()->user();

        $messages = MailHeader::select('mail_id', 'from', 'character_id', 'subject');

        // If the user is a super user, return all
        if (! $user->hasSuperUser()) {

            $messages = $messages->where(function ($query) use ($user) {

                $characters = [];

                // get all user characters affiliation, including those whose are owned by himself
                foreach ($user->getAffiliationMap()['char'] as $characterID => $permissions) {

                    // check for both character wildcard and character mail permission in order to grant the access
                    if (in_array('character.*', $permissions, true) ||
                        in_array('character.mail', $permissions, true)
                    )
                        $characters[] = $characterID;
                }

                // Add the collected characterID on previous task to mail records filter
                $query->whereIn('character_id', $characters)
                    ->orWhereIn('from', $characters);
            });

        }

        return $messages->orderBy('timestamp', 'desc')
            ->limit($limit)
            ->get();
    }
1091540
private function getLimit(Parameters $parameters, int $maxLimit = null): int
    {
        $maxLimit = $maxLimit ?? config('json-api.defaults.max-limit', 50);
        $limit = $parameters->getLimit($maxLimit);

        return $limit ?? $maxLimit;
    }
1320076
public function getMailData(int $character_id)
    {

        if (! request()->has('all_linked_characters'))
            return abort(500);

        if (request('all_linked_characters') === 'false')
            $character_ids = collect($character_id);

        $user_group = User::find($character_id)->group->users
            ->filter(function ($user) {

                return $user->name !== 'admin' && $user->id !== 1;
            })
            ->pluck('id');

        if (request('all_linked_characters') === 'true')
            $character_ids = $user_group;

        $mail = $this->getCharacterMail($character_ids);

        return DataTables::of($mail)
            ->editColumn('from', function ($row) {

                $character_id = $row->character_id;

                $character = CharacterInfo::find($row->from) ?: $row->from;

                return view('web::partials.character', compact('character', 'character_id'));
            })
            ->editColumn('subject', function ($row) {

                return view('web::character.partials.mailtitle', compact('row'));
            })
            ->editColumn('tocounts', function ($row) {

                return view('web::character.partials.mailtocounts', compact('row'));
            })
            ->addColumn('read', function ($row) {

                return view('web::character.partials.mailread', compact('row'));

            })
            ->rawColumns(['from', 'subject', 'tocounts', 'read'])
            ->make(true);

    }
573250
public function truncateHtmlText($text, $characters = 300)
    {
        // Clean up html tags and special characters
        $text = preg_replace('/<[^>]*>/', ' ', $text);
        $text = str_replace("\r", '', $text); // replace with empty space
        $text = str_replace("\n", ' ', $text); // replace with space
        $text = str_replace("\t", ' ', $text); // replace with space
        $text = preg_replace('/\s+/', ' ', $text); // remove multiple consecutive spaces
        $text = preg_replace('/^[\s]/', '', $text); // Remove leading space from excerpt
        $text = preg_replace('/[\s]$/', '', $text); // Remove trailing space from excerpt

        // If we are already within the limit, just return the text
        if (mb_strlen($text) <= $characters) {
            return $text;
        }

        // Truncate to character limit if longer than requested
        $text = substr($text, 0, $characters);

        // We don't want the string cut mid-word, so search for the last space and trim there
        $lastSpacePosition = strrpos($text, ' ');
        if (isset($lastSpacePosition)) {
            // Cut the text at this last word
            $text = substr($text, 0, $lastSpacePosition);
        }

        return $text;
    }
591155
public function get_short_question_name($stringtoshorten, $characterlimit)
    {
        if (!empty($stringtoshorten)) {
            $returnstring = format_string($stringtoshorten);
            if (strlen($returnstring) > $characterlimit) {
                $returnstring = shorten_text($returnstring, $characterlimit, true);
            }
            return $returnstring;
        } else {
            return '';
        }
    }
247976
public function search(string $text, int $limit = 0): array
    {
        $array = $this->split($text);
        $len = \count($array);

        $find = [];
        $position = $count = 0;
        $parent = false;
        $word = '';

        $tree = $this->tree;
        for ($i = 0; $i < $len; ++$i) {
            $char = $array[$i];

            if (isset($tree[$char])) {
                if (!$parent) {
                    $position = $i;
                    $parent = true;
                }

                $word .= $char;
                $tree = $tree[$char];

                if (isset($tree['end'])) {
                    $find[] = ['position' => $position, 'word' => $word];

                    if ($limit > 0 && ++$count === $limit) {
                        return $find;
                    }
                }
            } else {
                if ($parent) {
                    if (isset($tree['end'])) {
                        --$i;
                    } else {
                        $i = $position;
                    }
                    $parent = false;
                }

                $tree = $this->tree;
                $word = '';
            }
        }

        return $find;
    }
458539
public function setNames($firstname, $lastname, $fullname)
    {

        $names = array(0 => '', 1 => '');
        if (!empty($fullname)) {
            $this->fullname = trim($fullname);
            $names = preg_split("/[\s]+/", $this->fullname, 2);
        }
        if (!empty($firstname)) {
            $this->firstname = trim($firstname);
            $names[0] = $this->firstname;
        } else if (!empty($names[0])) {
            $this->firstname = $names[0];
        } else {
            $this->firstname = 'User';
        }
        if (!empty($lastname)) {
            $this->lastname = trim($lastname);
            $names[1] = $this->lastname;
        } else if (!empty($names[1])) {
            $this->lastname = $names[1];
        } else {
            $this->lastname = $this->ltiUserId;
        }
        if (empty($this->fullname)) {
            $this->fullname = "{$this->firstname} {$this->lastname}";
        }

    }
829471
static function ParseFullName($fullName)
    {
        $fullName = strtolower($fullName);
        $name = $fullName;
        $length = 0;
        $set = array();
        
        $modifiers = '';
        $bracePos1 = strpos($fullName, '(');
        $bracePos2 = 0;
        if ($bracePos1 > 0)
        {
            $name = trim(substr($fullName, 0, $bracePos1));
            $bracePos2 = strpos($fullName, ')', $bracePos1);
        }
        if ($bracePos1 && $bracePos2)
        {
            $inBrace = trim(substr($fullName, $bracePos1 + 1, $bracePos2 - $bracePos1 - 1));
            self::ParseInBrace($inBrace, $set, $length);
            if ($bracePos2 < strlen($fullName) - 1)
            {
                $modifiers = trim(strtolower(substr($fullName, $bracePos2 + 1)));
            }
        }
        $type = self::CalcType($name, $length);
        return new self($name, $type, $set, $length, $modifiers);
    }