[PR] 美容整形 at 東京

謎の文章メモ

teao ssh トンネル

研究 ajax 単語スコア付け wikipedia

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
 
-
|
|
|
|
|
!
#include <stdio.h>
main(){
  int var;
 
  var = 1;
 
  printf("adsf%d",var);
}
  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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
// PukiWiki - Yet another WikiWikiWeb clone.
// $Id: func.php,v 1.73.7 2006/06/06 16:41:39 miko Exp $
// Copyright (C)
//   2005-2006 PukiWiki Plus! Team
//   2002-2006 PukiWiki Developers Team
//   2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
// General functions
 
function is_interwiki($str)
{
    global $InterWikiName;
    return preg_match('/^' . $InterWikiName . '$/', $str);
}
 
function is_pagename($str)
{
    global $BracketName;
 
    $is_pagename = (! is_interwiki($str) &&
          preg_match('/^(?!\/)' . $BracketName . '$(?<!\/$)/', $str) &&
        ! preg_match('#(^|/)\.{1,2}(/|$)#', $str));
 
    if (defined('SOURCE_ENCODING')) {
        switch(SOURCE_ENCODING){
        case 'UTF-8': $pattern =
            '/^(?:[\x00-\x7F]|(?:[\xC0-\xDF][\x80-\xBF])|(?:[\xE0-\xEF][\x80-\xBF][\x80-\xBF]))+$/';
            break;
        case 'EUC-JP': $pattern =
            '/^(?:[\x00-\x7F]|(?:[\x8E\xA1-\xFE][\xA1-\xFE])|(?:\x8F[\xA1-\xFE][\xA1-\xFE]))+$/';
            break;
        }
        if (isset($pattern) && $pattern != '')
            $is_pagename = ($is_pagename && preg_match($pattern, $str));
    }
 
    return $is_pagename;
}
 
function is_url($str, $only_http = FALSE)
{
    $scheme = $only_http ? 'https?' : 'https?|ftp|news';
    return preg_match('/^(' . $scheme . ')(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]*)$/', $str);
}
 
// If the page exists
function is_page($page, $clearcache = FALSE)
{
    if ($clearcache) clearstatcache();
    return file_exists(get_filename($page));
}
 
function is_editable($page)
{
    global $cantedit;
    static $is_editable = array();
 
    if (! isset($is_editable[$page])) {
        $is_editable[$page] = (
            is_pagename($page) &&
            ! is_freeze($page) &&
            ! in_array($page, $cantedit)
        );
    }
 
    return $is_editable[$page];
}
 
function is_freeze($page, $clearcache = FALSE)
{
    global $function_freeze;
    static $is_freeze = array();
 
    if ($clearcache === TRUE) $is_freeze = array();
    if (isset($is_freeze[$page])) return $is_freeze[$page];
 
    if (! $function_freeze || ! is_page($page)) {
        $is_freeze[$page] = FALSE;
        return FALSE;
    } else {
        $fp = fopen(get_filename($page), 'rb') or
            die('is_freeze(): fopen() failed: ' . htmlspecialchars($page));
        flock($fp, LOCK_SH) or die('is_freeze(): flock() failed');
        rewind($fp);
        $buffer = fgets($fp, 9);
        flock($fp, LOCK_UN) or die('is_freeze(): flock() failed');
        fclose($fp) or die('is_freeze(): fclose() failed: ' . htmlspecialchars($page));
 
        $is_freeze[$page] = ($buffer != FALSE && rtrim($buffer, "\r\n") == '#freeze');
        return $is_freeze[$page];
    }
}
 
// Handling $non_list
// $non_list will be preg_quote($str, '/') later.
function check_non_list($page = '')
{
    global $non_list;
    static $regex;
 
    if (! isset($regex)) $regex = '/' . $non_list . '/';
 
    return preg_match($regex, $page);
}
 
// Auto template
function auto_template($page)
{
    global $auto_template_func, $auto_template_rules;
 
    if (! $auto_template_func) return '';
 
    $body = '';
    $matches = array();
    foreach ($auto_template_rules as $rule => $template) {
        $rule_pattrn = '/' . $rule . '/';
 
        if (! preg_match($rule_pattrn, $page, $matches)) continue;
 
        $template_page = preg_replace($rule_pattrn, $template, $page);
        if (! is_page($template_page)) continue;
 
        $body = join('', get_source($template_page));
 
        // Remove fixed-heading anchors
        $body = preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/m', '$1$2', $body);
 
        // Remove '#freeze'
        $body = preg_replace('/^#freeze\s*$/m', '', $body);
 
        $count = count($matches);
        for ($i = 0; $i < $count; $i++)
            $body = str_replace('$' . $i, $matches[$i], $body);
 
        break;
    }
    return $body;
}
 
// Expand all search-words to regexes and push them into an array
function get_search_words($words = array(), $do_escape = FALSE)
{
    static $init, $mb_convert_kana, $pre, $post, $quote = '/';
 
    if (! isset($init)) {
        // function: mb_convert_kana() is for Japanese code only
        if (LANG == 'ja' && function_exists('mb_convert_kana')) {
            $mb_convert_kana = create_function('$str, $option',
                'return mb_convert_kana($str, $option, SOURCE_ENCODING);');
        } else {
            $mb_convert_kana = create_function('$str, $option',
                'return $str;');
        }
        if (SOURCE_ENCODING == 'EUC-JP') {
            // Perl memo - Correct pattern-matching with EUC-JP
            // http://www.din.or.jp/~ohzaki/perl.htm#JP_Match (Japanese)
            $pre  = '(?<!\x8F)';
            $post =    '(?=(?:[\xA1-\xFE][\xA1-\xFE])*' . // JIS X 0208
                '(?:[\x00-\x7F\x8E\x8F]|\z))';     // ASCII, SS2, SS3, or the last
        } else {
            $pre = $post = '';
        }
        $init = TRUE;
    }
 
    if (! is_array($words)) $words = array($words);
 
    // Generate regex for the words
    $regex = array();
    foreach ($words as $word) {
        $word = trim($word);
        if ($word == '') continue;
 
        // Normalize: ASCII letters = to single-byte. Others = to Zenkaku and Katakana
        $word_nm = $mb_convert_kana($word, 'aKCV');
        $nmlen   = mb_strlen($word_nm, SOURCE_ENCODING);
 
        // Each chars may be served ...
        $chars = array();
        for ($pos = 0; $pos < $nmlen; $pos++) {
            $char = mb_substr($word_nm, $pos, 1, SOURCE_ENCODING);
 
            // Just normalized one? (ASCII char or Zenkaku-Katakana?)
            $or = array(preg_quote($do_escape ? htmlspecialchars($char) : $char, $quote));
            if (strlen($char) == 1) {
                // An ASCII (single-byte) character
                foreach (array(strtoupper($char), strtolower($char)) as $_char) {
                    if ($char != '&') $or[] = preg_quote($_char, $quote); // As-is?
                    $ascii = ord($_char);
                    $or[] = sprintf('&#(?:%d|x%x);', $ascii, $ascii); // As an entity reference?
                    $or[] = preg_quote($mb_convert_kana($_char, 'A'), $quote); // As Zenkaku?
                }
            } else {
                // NEVER COME HERE with mb_substr(string, start, length, 'ASCII')
                // A multi-byte character
                $or[] = preg_quote($mb_convert_kana($char, 'c'), $quote); // As Hiragana?
                $or[] = preg_quote($mb_convert_kana($char, 'k'), $quote); // As Hankaku-Katakana?
            }
            $chars[] = '(?:' . join('|', array_unique($or)) . ')'; // Regex for the character
        }
 
        $regex[$word] = $pre . join('', $chars) . $post; // For the word
    }
 
    return $regex; // For all words
}
 

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2007-01-06 (土) 14:16:17 (3878d)