You are here

protected function Twig_Test_EscapingTest::codepointToUtf8 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/test/Twig/Tests/escapingTest.php \Twig_Test_EscapingTest::codepointToUtf8()

Convert a Unicode Codepoint to a literal UTF-8 character.

Parameters

int $codepoint Unicode codepoint in hex notation:

Return value

string UTF-8 literal string

4 calls to Twig_Test_EscapingTest::codepointToUtf8()
Twig_Test_EscapingTest::testCssEscapingEscapesOwaspRecommendedRanges in vendor/twig/twig/test/Twig/Tests/escapingTest.php
Twig_Test_EscapingTest::testHtmlAttributeEscapingEscapesOwaspRecommendedRanges in vendor/twig/twig/test/Twig/Tests/escapingTest.php
Twig_Test_EscapingTest::testJavascriptEscapingEscapesOwaspRecommendedRanges in vendor/twig/twig/test/Twig/Tests/escapingTest.php
Twig_Test_EscapingTest::testUnicodeCodepointConversionToUtf8 in vendor/twig/twig/test/Twig/Tests/escapingTest.php
Only testing the first few 2 ranges on this prot. function as that's all these other range tests require.

File

vendor/twig/twig/test/Twig/Tests/escapingTest.php, line 233

Class

Twig_Test_EscapingTest
This class is adapted from code coming from Zend Framework.

Code

protected function codepointToUtf8($codepoint) {
  if ($codepoint < 0x80) {
    return chr($codepoint);
  }
  if ($codepoint < 0x800) {
    return chr($codepoint >> 6 & 0x3f | 0xc0) . chr($codepoint & 0x3f | 0x80);
  }
  if ($codepoint < 0x10000) {
    return chr($codepoint >> 12 & 0xf | 0xe0) . chr($codepoint >> 6 & 0x3f | 0x80) . chr($codepoint & 0x3f | 0x80);
  }
  if ($codepoint < 0x110000) {
    return chr($codepoint >> 18 & 0x7 | 0xf0) . chr($codepoint >> 12 & 0x3f | 0x80) . chr($codepoint >> 6 & 0x3f | 0x80) . chr($codepoint & 0x3f | 0x80);
  }
  throw new Exception('Codepoint requested outside of Unicode range');
}