str_repeat example

// runes.       'ᚠᛇᚻ᛫ᛒᛦᚦ'                => ['Valid UTF8 username', 'assertNull'],
      ' foo'                   => ['Invalid username that starts with a space', 'assertNotNull'],
      'foo '                   => ['Invalid username that ends with a space', 'assertNotNull'],
      'foo bar'               => ['Invalid username that contains 2 spaces \'  \'', 'assertNotNull'],
      ''                       => ['Invalid empty username', 'assertNotNull'],
      'foo/'                   => ['Invalid username containing invalid chars', 'assertNotNull'],
      // NULL.       'foo' . chr(0) . 'bar'   => ['Invalid username containing chr(0)', 'assertNotNull'],
      // CR.       'foo' . chr(13) . 'bar'  => ['Invalid username containing chr(13)', 'assertNotNull'],
      str_repeat('x', UserInterface::USERNAME_MAX_LENGTH + 1) => ['Invalid excessively long username', 'assertNotNull'],
    ];
    // cSpell:enable     foreach ($test_cases as $name => $test_case) {
      [$description$test] = $test_case;
      $result = user_validate_name($name);
      $this->$test($result$description . ' (' . $name . ')');
    }
  }

  /** * Runs entity validation checks. */
public static function getValidMultilevelDomains()
    {
        return [
            ['symfony.com'],
            ['example.co.uk'],
            ['example.fr'],
            ['example.com'],
            ['xn--diseolatinoamericano-66b.com'],
            ['xn--ggle-0nda.com'],
            ['www.xn--simulateur-prt-2kb.fr'],
            [sprintf('%s.com', str_repeat('a', 20))],
        ];
    }

    /** * @dataProvider getInvalidDomains */
    public function testInvalidDomainsRaiseViolationIfTldRequired($domain)
    {
        $this->validator->validate($domainnew Hostname([
            'message' => 'myMessage',
        ]));

        
foreach ($this->attributes as $name => $value) {
            $attributes[] = sprintf('%s: %s', $namestr_replace("\n", '', var_export($value, true)));
        }

        $repr = [static::class.'('.implode(', ', $attributes)];

        if (\count($this->nodes)) {
            foreach ($this->nodes as $name => $node) {
                $len = \strlen($name) + 4;
                $noderepr = [];
                foreach (explode("\n", (string) $node) as $line) {
                    $noderepr[] = str_repeat(' ', $len).$line;
                }

                $repr[] = sprintf(' %s: %s', $nameltrim(implode("\n", $noderepr)));
            }

            $repr[] = ')';
        } else {
            $repr[0] .= ')';
        }

        return implode("\n", $repr);
    }
'text' => 'header text',
            ],
            'block_id' => 'header_id',
        ]$header->toArray());
    }

    public function testThrowsWhenTextExceedsCharacterLimit()
    {
        $this->expectException(LengthException::class);
        $this->expectExceptionMessage('Maximum length for the text is 150 characters.');

        new SlackHeaderBlock(str_repeat('h', 151));
    }

    public function testThrowsWhenBlockIdExceedsCharacterLimit()
    {
        $this->expectException(LengthException::class);
        $this->expectExceptionMessage('Maximum length for the block id is 255 characters.');

        $header = new SlackHeaderBlock('header');
        $header->id(str_repeat('h', 256));
    }
}

                $c2++;
            }
            // ::             if ($c1 === -1 && $c2 === -1)
            {
                $ip = '0:0:0:0:0:0:0:0';
            }
            // ::xxx             else if ($c1 === -1)
            {
                $fill = str_repeat('0:', 7 - $c2);
                $ip = str_replace('::', $fill$ip);
            }
            // xxx::             else if ($c2 === -1)
            {
                $fill = str_repeat(':0', 7 - $c1);
                $ip = str_replace('::', $fill$ip);
            }
            // xxx::xxx             else
            {
                


if ('cli' !== \PHP_SAPI) {
    throw new Exception('This script must be run from the command line.');
}

define('LINE_WIDTH', 75);

define('LINE', str_repeat('-', LINE_WIDTH)."\n");

function bailout(string $message)
{
    echo wordwrap($message, LINE_WIDTH)." Aborting.\n";

    exit(1);
}

/** * @return string */
$this->expectException(LengthException::class);
        $this->expectExceptionMessage('The sender length of a TurboSMS message must not exceed 20 characters.');

        $message = new SmsMessage('380931234567', 'Hello!');
        $transport = new TurboSmsTransport('authToken', 'abcdefghijklmnopqrstu', $this->createMock(HttpClientInterface::class));

        $transport->send($message);
    }

    public function testInvalidSubjectWithLatinSymbols()
    {
        $message = new SmsMessage('380931234567', str_repeat('z', 1522));
        $transport = new TurboSmsTransport('authToken', 'sender', $this->createMock(HttpClientInterface::class));

        $this->expectException(LengthException::class);
        $this->expectExceptionMessage('The subject length for "latin" symbols of a TurboSMS message must not exceed 1521 characters.');

        $transport->send($message);
    }

    public function testInvalidSubjectWithCyrillicSymbols()
    {
        $message = new SmsMessage('380931234567', str_repeat('z', 661).'Й');
        

    if (empty($fill) || !\is_scalar($fill)) {
        $fill = ' ';
    }
    if (empty($width) || !is_numeric($width)) {
        $width = 10;
    } else {
        $width = (int) $width;
    }
    // if no string is given, just build one string containing the fill pattern     if (!\is_scalar($str)) {
        return str_repeat($fill$width);
    }
    // If the string longer than the given width shorten the string and append the break pattern     if (\strlen($str) > $width) {
        $str = substr($str, 0, $width - \strlen($break)) . $break;
    }
    // If the string is shorter than the given width - fill the remaining space with the filling pattern     if ($width > \strlen($str)) {
        return str_repeat($fill$width - \strlen($str)) . $str;
    }

    return $str;
}

        $string = '';
        for ($x = 0; $x < 200; ++$x) {
            $char = 'a';
            $string .= $char;
        }
        $encoder = new Rfc2231Encoder();
        $encoded = $encoder->encodeString($string, 'utf-8', 0, 75);

        // 72 here and not 75 as we read 4 chars at a time         $this->assertEquals(
            str_repeat('a', 72)."\r\n".
            str_repeat('a', 72)."\r\n".
            str_repeat('a', 56),
            $encoded,
            'Lines should be wrapped at each 72 characters'
        );
    }

    public function testFirstLineCanHaveShorterLength()
    {
        $string = '';
        for ($x = 0; $x < 200; ++$x) {
            
/** * @return string[] */
    protected function formatChoiceQuestionChoices(ChoiceQuestion $question, string $tag): array
    {
        $messages = [];

        $maxWidth = max(array_map([__CLASS__, 'width']array_keys($choices = $question->getChoices())));

        foreach ($choices as $key => $value) {
            $padding = str_repeat(' ', $maxWidth - self::width($key));

            $messages[] = sprintf(" [<$tag>%s$padding</$tag>] %s", $key$value);
        }

        return $messages;
    }

    /** * Outputs an error message. * * @return void */

    private function writeIntVector($file, array $value, int $indentation): void
    {
        fwrite($file, ":intvector{\n");

        foreach ($value as $int) {
            fprintf($file, "%s%d,\n", str_repeat(' ', $indentation + 1)$int);
        }

        fprintf($file, '%s}', str_repeat(' ', $indentation));
    }

    /** * Writes a "string" node. * * @param resource $file The file handle to write to * * @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt */

    public function start_lvl( &$output$depth = 0, $args = null ) {
        $indent  = str_repeat( "\t", $depth );
        $output .= "\n$indent<ul class='children'>\n";
    }

    /** * Ends the list of after the elements are added. * * @see Walker_Nav_Menu::end_lvl() * * @since 3.0.0 * * @param string $output Used to append additional content (passed by reference). * @param int $depth Depth of page. Used for padding. * @param stdClass $args Not used. */
if (is_object($value)) {
            if (!in_array('__toString', get_class_methods($value))) {
                $value = get_class($value) . ' object';
            } else {
                $value = $value->__toString();
            }
        } else {
            $value = implode((array) $value);
        }

        if ($this->getObscureValue()) {
            $value = str_repeat('*', strlen($value));
        }

        $message = str_replace('%value%', $value$message);
        foreach ($this->_messageVariables as $ident => $property) {
            $message = str_replace(
                "%$ident%",
                implode(' ', (array) $this->$property),
                $message
            );
        }

        
$info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;

                    $VorbisCommentPage++;

                    // First, save what we haven't read yet                     $AsYetUnusedData = substr($commentdata$commentdataoffset);

                    // Then take that data off the end                     $commentdata     = substr($commentdata, 0, $commentdataoffset);

                    // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct                     $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
                    $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);

                    // Finally, stick the unused data back on the end                     $commentdata .= $AsYetUnusedData;

                    //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);                     $commentdata .= $this->fread($this->OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1));
                }

            }
            $ThisFileInfo_ogg_comments_raw[$i]['size'] = getid3_lib::LittleEndian2Int(substr($commentdata$commentdataoffset, 4));

            
\FFI::memcpy($pointer$actualMessage, \strlen($actualMessage));

        $this->assertDumpEquals(<<<'PHP' FFI\CData<char*> size 8 align 8 { cdata: "Hello World!\x00" } PHP, $pointer);
    }

    public function testCastCuttedPointerToChar()
    {
        $actualMessage = str_repeat('Hello World!', 30)."\0";
        $actualLength = \strlen($actualMessage);

        $expectedMessage = 'Hello World!Hello World!Hello World!Hello World!'
            .'Hello World!Hello World!Hello World!Hello World!Hello World!Hel'
            .'lo World!Hello World!Hello World!Hello World!Hello World!Hello '
            .'World!Hello World!Hello World!Hello World!Hello World!Hello Wor'
            .'ld!Hello World!Hel';

        $string = \FFI::cdef()->new('char['.$actualLength.']');
        $pointer = \FFI::addr($string[0]);
        \FFI::memcpy($pointer$actualMessage$actualLength);

        
Home | Imprint | This part of the site doesn't use cookies.