/var/www/hkosl.com/nick/codeigniter/application/vendor/gettext/gettext/src/Extractors/PhpCode.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php

namespace Gettext\Extractors;

use 
Gettext\Translations;
use 
Gettext\Utils\PhpFunctionsScanner;

/**
 * Class to get gettext strings from php files returning arrays.
 */
class PhpCode extends Extractor implements ExtractorInterface
{
    public static 
$options = [
         
// - false: to not extract comments
         // - empty string: to extract all comments
         // - non-empty string: to extract comments that start with that string
         // - array with strings to extract comments format.
        
'extractComments' => false,

        
'constants' => [],

        
'functions' => [
            
'gettext' => 'gettext',
            
'__' => 'gettext',
            
'ngettext' => 'ngettext',
            
'n__' => 'ngettext',
            
'pgettext' => 'pgettext',
            
'p__' => 'pgettext',
            
'dgettext' => 'dgettext',
            
'd__' => 'dgettext',
            
'dngettext' => 'dngettext',
            
'dn__' => 'dngettext',
            
'dpgettext' => 'dpgettext',
            
'dp__' => 'dpgettext',
            
'npgettext' => 'npgettext',
            
'np__' => 'npgettext',
            
'dnpgettext' => 'dnpgettext',
            
'dnp__' => 'dnpgettext',
            
'noop' => 'noop',
            
'noop__' => 'noop',
        ],
    ];

    
/**
     * {@inheritdoc}
     */
    
public static function fromString($stringTranslations $translations, array $options = [])
    {
        
$options += static::$options;

        
$functions = new PhpFunctionsScanner($string);

        if (
$options['extractComments'] !== false) {
            
$functions->enableCommentsExtraction($options['extractComments']);
        }

        
$functions->saveGettextFunctions($translations$options);
    }

    
/**
     * Decodes a T_CONSTANT_ENCAPSED_STRING string.
     *
     * @param string $value
     *
     * @return string
     */
    
public static function convertString($value)
    {
        if (
strpos($value'\\') === false) {
            return 
substr($value1, -1);
        }

        if (
$value[0] === "'") {
            return 
strtr(substr($value1, -1), ['\\\\' => '\\''\\\'' => '\'']);
        }

        
$value substr($value1, -1);

        return 
preg_replace_callback(
            
'/\\\(n|r|t|v|e|f|\$|"|\\\|x[0-9A-Fa-f]{1,2}|u{[0-9a-f]{1,6}}|[0-7]{1,3})/',
            function (
$match) {
                switch (
$match[1][0]) {
                    case 
'n':
                        return 
"\n";
                    case 
'r':
                        return 
"\r";
                    case 
't':
                        return 
"\t";
                    case 
'v':
                        return 
"\v";
                    case 
'e':
                        return 
"\e";
                    case 
'f':
                        return 
"\f";
                    case 
'$':
                        return 
'$';
                    case 
'"':
                        return 
'"';
                    case 
'\\':
                        return 
'\\';
                    case 
'x':
                        return 
chr(hexdec(substr($match[0], 1)));
                    case 
'u':
                        return 
self::unicodeChar(hexdec(substr($match[0], 1)));
                    default:
                        return 
chr(octdec($match[0]));
                }
            },
            
$value
        
);
    }

    
//http://php.net/manual/en/function.chr.php#118804
    
private static function unicodeChar($dec)
    {
        if (
$dec 0x80) {
            return 
chr($dec);
        }

        if (
$dec 0x0800) {
            return 
chr(0xC0 + ($dec >> 6))
                .
chr(0x80 + ($dec 0x3f));
        }

        if (
$dec 0x010000) {
            return 
chr(0xE0 + ($dec >> 12))
                    .
chr(0x80 + (($dec >> 6) & 0x3f))
                    .
chr(0x80 + ($dec 0x3f));
        }

        if (
$dec 0x200000) {
            return 
chr(0xF0 + ($dec >> 18))
                    .
chr(0x80 + (($dec >> 12) & 0x3f))
                    .
chr(0x80 + (($dec >> 6) & 0x3f))
                    .
chr(0x80 + ($dec 0x3f));
        }
    }
}