Skip to content

Commit 2489f76

Browse files
committed
language-specific syntax highlighting
1 parent ee97809 commit 2489f76

31 files changed

+242
-136
lines changed

count-bytes/perl5.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
The core `length` function returns the number of bytes when called on a byte
44
string instead of a character string.
55

6-
$count = length $utf8;
6+
```perl
7+
$count = length $utf8;
8+
```

count-bytes/perl6.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
The `bytes` method is available for buffers (`Buf` objects).
44

5-
$count = $utf8.bytes;
5+
```perl
6+
$count = $utf8.bytes;
7+
```

count-characters/javascript.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
The [Punycode.js](https://github.com/bestiejs/punycode.js) library can be used
66
to count code points.
77

8-
var puny = require('punycode');
8+
```javascript
9+
var puny = require('punycode');
910

10-
$count = puny.ucs2.decode(str).length;
11+
$count = puny.ucs2.decode(str).length;
12+
```

count-characters/perl5.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,36 @@
55
The core `length` function returns the number of code points when called on a
66
character string (instead of a byte string).
77

8-
$count = length $str;
8+
```perl
9+
$count = length $str;
10+
```
911

1012
## Grapheme clusters
1113

1214
There is no core function to count the number of grapheme clusters; however,
1315
either of the following examples will perform the task.
1416

15-
$count = () = $str =~ /\X/g;
17+
```perl
18+
$count = () = $str =~ /\X/g;
1619

17-
$count++ while $str =~ /\X/g;
20+
$count++ while $str =~ /\X/g;
21+
```
1822

1923
The CPAN module
2024
[Unicode::GCString](https://metacpan.org/module/Unicode::GCString) can also be
2125
used on character strings.
2226

23-
use Unicode::GCString;
27+
```perl
28+
use Unicode::GCString;
2429

25-
$count = Unicode::GCString->new($str)->length;
30+
$count = Unicode::GCString->new($str)->length;
31+
```
2632

2733
As well as the CPAN module
2834
[Unicode::Util](Unicode::GCStrin://metacpan.org/module/Unicode::Util).
2935

30-
use Unicode::Util qw( grapheme_length );
36+
```perl
37+
use Unicode::Util qw( grapheme_length );
3138

32-
$count = grapheme_length($str);
39+
$count = grapheme_length($str);
40+
```

count-characters/perl6.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
The `codes` method is available for strings (`Str` objects).
66

7-
$count = $str.codes;
7+
```perl
8+
$count = $str.codes;
9+
```
810

911
## Grapheme clusters
1012

1113
The `graphemes` method is available for strings (`Str` objects).
1214

13-
$count = $str.graphemes;
15+
```perl
16+
$count = $str.graphemes;
17+
```

count-characters/php.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ The `mb_strlen` function is available for strings in PHP 4.0.6 and requires the
66
encoding of the string to either passed as the second argument or set in
77
`mbstring.internal_encoding`.
88

9-
$count = mb_strlen($str, 'UTF-8');
9+
```php
10+
$count = mb_strlen($str, 'UTF-8');
11+
```
1012

1113
## Grapheme clusters
1214

1315
The `grapheme_strlen` function is available for UTF-8 strings in PHP 5.3.0 or
1416
the PECL extension [intl](http://pecl.php.net/package/intl).
1517

16-
$count = grapheme_strlen($str);
18+
```php
19+
$count = grapheme_strlen($str);
20+
```

encode-decode/perl5.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Encode and decode in Perl 5
22

3-
use Encode;
3+
```perl
4+
use Encode;
45

5-
$utf8 = encode('UTF-8', $str);
6-
$str = decode('UTF-8', $utf8);
6+
$utf8 = encode('UTF-8', $str);
7+
$str = decode('UTF-8', $utf8);
8+
```

encode-decode/perl6.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
UTF-8 is the default.
44

5-
$utf8 = $str.encode;
6-
$str = $utf8.decode;
5+
```perl
6+
$utf8 = $str.encode;
7+
$str = $utf8.decode;
8+
```
79

810
Other encodings can be explicitly specified.
911

10-
$utf16 = $str.encode('UTF-16');
11-
$str = $utf16.decode('UTF-16');
12+
```perl
13+
$utf16 = $str.encode('UTF-16');
14+
$str = $utf16.decode('UTF-16');
15+
```

io/perl5.md

+19-9
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,37 @@ and encode on output.
99
All standard streams and filehandles. This does not include command-line
1010
arguments.
1111

12-
use open qw( :encoding(UTF-8) :std );
12+
```perl
13+
use open qw( :encoding(UTF-8) :std );
14+
```
1315

1416
Alternately, individual streams and filehandles can be handled as follows.
1517

1618
## Standard streams
1719

18-
binmode STDIN, ':encoding(UTF-8)';
19-
binmode STDOUT, ':encoding(UTF-8)';
20-
binmode STDERR, ':encoding(UTF-8)';
20+
```perl
21+
binmode STDIN, ':encoding(UTF-8)';
22+
binmode STDOUT, ':encoding(UTF-8)';
23+
binmode STDERR, ':encoding(UTF-8)';
24+
```
2125

2226
## Existing filehandles
2327

24-
binmode $fh, ':encoding(UTF-8)';
28+
```perl
29+
binmode $fh, ':encoding(UTF-8)';
30+
```
2531

2632
## New filehandles
2733

28-
open my $in_fh, '<:encoding(UTF-8)', $path;
29-
open my $out_fh, '>:encoding(UTF-8)', $path;
34+
```perl
35+
open my $in_fh, '<:encoding(UTF-8)', $path;
36+
open my $out_fh, '>:encoding(UTF-8)', $path;
37+
```
3038

3139
## Command-line arguments
3240

33-
use Encode;
41+
```perl
42+
use Encode;
3443

35-
@args = map { decode('UTF-8', $_) } @ARGV;
44+
@args = map { decode('UTF-8', $_) } @ARGV;
45+
```

io/perl6.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ follows.
66

77
## Standard streams
88

9-
$*IN.encoding = 'UTF-16';
10-
$*OUT.encoding = 'UTF-16';
11-
$*ERR.encoding = 'UTF-16';
9+
```perl
10+
$*IN.encoding = 'UTF-16';
11+
$*OUT.encoding = 'UTF-16';
12+
$*ERR.encoding = 'UTF-16';
13+
```
1214

1315
## Existing filehandles
1416

15-
$fh.encoding = 'UTF-16';
17+
```perl
18+
$fh.encoding = 'UTF-16';
19+
```
1620

1721
## New filehandles
1822

19-
my $in_fh = open $path, :r, :enc<UTF-16>;
20-
my $out_fh = open $path, :w, :enc<UTF-16>;
23+
```perl
24+
my $in_fh = open $path, :r, :enc<UTF-16>;
25+
my $out_fh = open $path, :w, :enc<UTF-16>;
26+
```

letter-casing/go.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
Letter casing functions are available in the core `strings` package and always
44
have Unicode semantics.
55

6-
lowercase = strings.ToLower(str)
7-
uppercase = strings.ToUpper(str)
8-
titlecase = strings.ToTitle(str) // every character
9-
titlecase = strings.Title(str) // first character of each word
6+
```go
7+
lowercase = strings.ToLower(str)
8+
uppercase = strings.ToUpper(str)
9+
titlecase = strings.ToTitle(str) // every character
10+
titlecase = strings.Title(str) // first character of each word
11+
```
1012

1113
Although there is no case folding function for strings, there is a caseless
1214
equality function that uses case folding,
1315

14-
strings.EqualFold(str1, str2)
16+
```go
17+
strings.EqualFold(str1, str2)
18+
```

letter-casing/perl5.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
Letter casing functions are available in the core language and have Unicode
44
semantics for character strings but ASCII semantics for byte strings.
55

6-
$lowercase = lc $str;
7-
$uppercase = uc $str;
8-
$titlecase = ucfirst $str;
6+
```perl
7+
$lowercase = lc $str;
8+
$uppercase = uc $str;
9+
$titlecase = ucfirst $str;
910

10-
use v5.16;
11-
$casefold = fc $str;
11+
use v5.16;
12+
$casefold = fc $str;
13+
```
1214

1315
The `fc` function was added in Perl 5.16 and requires `use v5.16` or
1416
`use feature 'fc'`. The CPAN module `Unicode::CaseFold` provides the `fc`
1517
function for Perl 5.8.1 or greater.
1618

17-
use Unicode::CaseFold;
18-
$casefold = fc $str;
19+
```perl
20+
use Unicode::CaseFold;
21+
$casefold = fc $str;
22+
```

letter-casing/perl6.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Letter casing methods are available for strings (`Str` objects) in the core
44
language and always have Unicode semantics.
55

6-
$lowercase = $str.lc;
7-
$uppercase = $str.uc;
8-
$titlecase = $str.tc;
9-
$casefold = $str.fc;
6+
```perl
7+
$lowercase = $str.lc;
8+
$uppercase = $str.uc;
9+
$titlecase = $str.tc;
10+
$casefold = $str.fc;
11+
```

letter-casing/php.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
Letter casing functions are available in the core language and have Unicode
44
semantics.
55

6-
$lowercase = mb_convert_case($str, MB_CASE_UPPER, 'UTF-8');
7-
$uppercase = mb_convert_case($str, MB_CASE_LOWER, 'UTF-8');
8-
$titlecase = mb_convert_case($str, MB_CASE_TITLE, 'UTF-8');
9-
# case folding?
6+
```php
7+
$lowercase = mb_convert_case($str, MB_CASE_UPPER, 'UTF-8');
8+
$uppercase = mb_convert_case($str, MB_CASE_LOWER, 'UTF-8');
9+
$titlecase = mb_convert_case($str, MB_CASE_TITLE, 'UTF-8');
10+
# case folding?
11+
```
1012

1113
The `mb_convert_case` function was added in PHP 4.3.

letter-casing/python.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
Letter casing methods are available for strings (`str` objects) in the core
44
language and always have Unicode semantics.
55

6-
lowercase = str.lower
7-
uppercase = str.upper
8-
titlecase = str.capitalize
9-
casefold = str.casefold
6+
```python
7+
lowercase = str.lower
8+
uppercase = str.upper
9+
titlecase = str.capitalize
10+
casefold = str.casefold
11+
```
1012

1113
The `casefold` method was added in Python 3.3.

letter-casing/ruby.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Letter casing functionality with Unicode semantics is not available in the core
44
language, only ASCII semantics. The Ruby gem `unicode_utils` provides this
55
functionality.
66

7-
require 'unicode_utils'
7+
```ruby
8+
require 'unicode_utils'
89

9-
lowercase = UnicodeUtils.downcase(str)
10-
uppercase = UnicodeUtils.upcase(str)
11-
titlecase = UnicodeUtils.titlecase(str)
12-
casefold = UnicodeUtils.casefold(str)
10+
lowercase = UnicodeUtils.downcase(str)
11+
uppercase = UnicodeUtils.upcase(str)
12+
titlecase = UnicodeUtils.titlecase(str)
13+
casefold = UnicodeUtils.casefold(str)
14+
```

normalization/go.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Unicode normalization is available in the
44
[unicode/norm](http://godoc.org/code.google.com/p/go.text/unicode/norm) package
55
from the [go.text](http://godoc.org/code.google.com/p/go.text) project.
66

7-
import "code.google.com/p/go.text/unicode/norm"
7+
```go
8+
import "code.google.com/p/go.text/unicode/norm"
89

9-
nfd := norm.NFD.String(str)
10-
nfc := norm.NFC.String(str)
11-
nfkd := norm.NFKD.String(str)
12-
nfkc := norm.NFKC.String(str)
10+
nfd := norm.NFD.String(str)
11+
nfc := norm.NFC.String(str)
12+
nfkd := norm.NFKD.String(str)
13+
nfkc := norm.NFKC.String(str)
14+
```

normalization/java.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Unicode normalization is available in the standard class
44
[java.text.Normalizer](http://docs.oracle.com/javase/7/docs/api/java/text/Normalizer.html)
55
with Java SE 6.
66

7-
import java.text.Normalizer;
7+
```java
8+
import java.text.Normalizer;
89

9-
nfd = Normalizer.normalize(str, Normalizer.Form.NFD);
10-
nfc = Normalizer.normalize(str, Normalizer.Form.NFC);
11-
nfkd = Normalizer.normalize(str, Normalizer.Form.NFKD);
12-
nfkc = Normalizer.normalize(str, Normalizer.Form.NFKC);
10+
nfd = Normalizer.normalize(str, Normalizer.Form.NFD);
11+
nfc = Normalizer.normalize(str, Normalizer.Form.NFC);
12+
nfkd = Normalizer.normalize(str, Normalizer.Form.NFKD);
13+
nfkc = Normalizer.normalize(str, Normalizer.Form.NFKC);
14+
```

normalization/javascript.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
Unicode normalization is available in the npm package
44
[unorm](https://npmjs.org/package/unorm).
55

6-
var unorm = require('unorm');
6+
```javascript
7+
var unorm = require('unorm');
78

8-
nfd = unorm.nfd(str);
9-
nfc = unorm.nfc(str);
10-
nfkd = unorm.nfkd(str);
11-
nfkc = unorm.nfkc(str);
9+
nfd = unorm.nfd(str);
10+
nfc = unorm.nfc(str);
11+
nfkd = unorm.nfkd(str);
12+
nfkc = unorm.nfkc(str);
13+
```

normalization/perl5.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Unicode normalization is available in the core module
44
[Unicode::Normalize](https://metacpan.org/pod/Unicode::Normalize) with Perl 5.8
55
and available on CPAN.
66

7-
use Unicode::Normalize;
7+
```perl
8+
use Unicode::Normalize;
89

9-
$nfd = NFD($str);
10-
$nfc = NFC($str);
11-
$nfkd = NFKD($str);
12-
$nfkc = NFKC($str);
10+
$nfd = NFD($str);
11+
$nfc = NFC($str);
12+
$nfkd = NFKD($str);
13+
$nfkc = NFKC($str);
14+
```

0 commit comments

Comments
 (0)