App-Greple

 view release on metacpan or  search on metacpan

Example.md  view on Meta::CPAN

	greple -pi -e 'cyclic redundancy c\w+' rfc*
	greple -o --joinby=' ' -ie 'cyclic redundancy c\w+' rfc*

### find Kanji and not CJKUnifiedIdeographs / 漢字だけど CJKUnifiedIdeographs じゃない文字を探す

	greple --inside='\p{Han}+' '[^\s\p{InCJKUnifiedIdeographs}]'
	
	# This works, but quite slow.  Not recommended.
	# 動くけどチョー遅いからこんなことしちゃ駄目よ。

### guess data encoding / 文字コードを自動判定する

	greple --icode=guess

### specify data encoding / 文字コードを指定する

	greple --icode=euc-jp
	greple --icode=shif-jis

### specify guessing code set / 自動判定するコードを指定する

	greple --icode=utf8,euc-jp,shift-jis,7bit-jis

### add to guessing code set / 自動判定するコードを追加する

	greple --icode=+euc-kr

---
## Filter / フィルター

### expand tabs before seach / タブを展開してから検索する

	greple -n --if=expand
	

README.md  view on Meta::CPAN

**-e**/**-v** (["PATTERNS"](#patterns))

## CHARACTER CODE

- **--icode**=_code_

    Target file is assumed to be encoded in utf8 by default.  Use this
    option to set specific encoding.  When handling Japanese text, you may
    choose from 7bit-jis (jis), euc-jp or shiftjis (sjis).  Multiple code
    can be supplied using multiple option or combined code names with
    space or comma, then file encoding is guessed from those code sets.
    Use encoding name `guess` for automatic recognition from default code
    list which is euc-jp and 7bit-jis.  Following commands are all
    equivalent.

        greple --icode=guess ...
        greple --icode=euc-jp,7bit-jis ...
        greple --icode=euc-jp --icode=7bit-jis ...

    Default code set are always included suspect code list.  If you have
    just one code adding to suspect list, put + mark before the code name.
    Next example does automatic code detection from euc-kr, ascii, utf8
    and UTF-16/32.

        greple --icode=+euc-kr ...

RIPGREP-STUDY.md  view on Meta::CPAN

4. 渡せない場合は `rg --files`(ファイル列挙のみ)にフォールバック — それでも
   .gitignore 尊重・バイナリスキップの恩恵はある

**正しさの条件**: プリフィルタは「greple がマッチするファイルの上位集合」を返す必要がある。
注意点と対策:

| 懸念 | 対策 |
|---|---|
| 正規表現方言差(後読み等) | `-P` (PCRE2) を使う。変換不能なら素通しフォールバック |
| 行跨ぎパターン | `rg -U`(マルチライン)を付ける |
| 非 UTF-8 ファイル(--icode) | `rg -E <encoding>` にマッピング。guess 時は素通し |
| `--if` フィルタ対象(zip 等) | rg では判定不能 → 素通し(従来どおり greple が処理) |
| 大文字小文字 (`-i`) | `rg -i` を連動 |
| must/need の複数パターン | 各陽性パターンの OR で `-e` を並べれば上位集合になる |

安全側に倒す(迷ったら素通し)設計なら結果の正しさは保たれ、性能だけが段階的に向上する。

**効果**: マッチが疎な大規模ツリーで支配的な「マッチしないファイルの処理」を rg の速度
(並列走査 + .gitignore/バイナリスキップ)で消せる。実測 3000 ファイルで 5 倍、
実プロジェクトの巨大ツリーでは桁違いになる。greple の主用途(ドキュメント・コード検索)で
最も体感が大きいのはこのケース。

script/greple  view on Meta::CPAN

}

## setup file encoding
if (@opt_icode) {
    @opt_icode = map { split /[,\s]+/ } @opt_icode;
    if (grep { s/^\+// } @opt_icode) {
	unshift @opt_icode, @default_icode_list;
    }
    @opt_icode = uniq @opt_icode;
    if (@opt_icode > 1) {
	@opt_icode = grep { !/(?:auto|guess)$/i } @opt_icode;
	Encode::Guess->set_suspects(@opt_icode);
	$file_code = 'Guess';
    }
    elsif ($opt_icode[0] =~ /^(?:guess|auto)$/i) {
	Encode::Guess->set_suspects(@default_icode_list);
	$file_code = 'Guess';
    } else {
	$file_code = $opt_icode[0];
    }
}
else {
    $file_code = $default_icode;
}

script/greple  view on Meta::CPAN



=over 7

=item B<--icode>=I<code>

Target file is assumed to be encoded in utf8 by default.  Use this
option to set specific encoding.  When handling Japanese text, you may
choose from 7bit-jis (jis), euc-jp or shiftjis (sjis).  Multiple code
can be supplied using multiple option or combined code names with
space or comma, then file encoding is guessed from those code sets.
Use encoding name C<guess> for automatic recognition from default code
list which is euc-jp and 7bit-jis.  Following commands are all
equivalent.

    greple --icode=guess ...
    greple --icode=euc-jp,7bit-jis ...
    greple --icode=euc-jp --icode=7bit-jis ...

Default code set are always included suspect code list.  If you have
just one code adding to suspect list, put + mark before the code name.
Next example does automatic code detection from euc-kr, ascii, utf8
and UTF-16/32.

    greple --icode=+euc-kr ...

t/15_encoding.t  view on Meta::CPAN

use open IO => ':utf8';

use lib '.';
use t::Util;

$ENV{NO_COLOR} = 1;

like(run(q(--icode euc-jp いろは t/SAMPLE_euc-jp.txt))->stdout,
     qr/いろは/, "euc-jp");

like(run(q(--icode guess いろは t/SAMPLE_euc-jp.txt))->stdout,
     qr/いろは/, "guess euc");

like(run(q(--icode shift-jis いろは t/SAMPLE_sjis.txt))->stdout,
     qr/いろは/, "shift-jis");

like(run(q(--icode +shift-jis いろは t/SAMPLE_sjis.txt))->stdout,
     qr/いろは/, "guess shift-jis");

done_testing;



( run in 1.422 second using v1.01-cache-2.11-cpan-7fcb06a456a )