File: user_property.rs

package info (click to toggle)
rust-onig 6.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 308 kB
  • sloc: makefile: 4
file content (38 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download | duplicates (3)
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
extern crate onig;

use onig::*;
use std::str;

fn main() {
    define_user_property(
        "HandakuonHiragana",
        &[
            (0x3071, 0x3071), // PA
            (0x3074, 0x3074), // PI
            (0x3077, 0x3077), // PU
            (0x307a, 0x307a), // PE
            (0x307d, 0x307d), // PO
        ],
    );

    // "PA PI PU PE PO a"
    let hay = [
        0xe3, 0x81, 0xb1, 0xe3, 0x81, 0xb4, 0xe3, 0x81, 0xb7, 0xe3, 0x81, 0xba, 0xe3, 0x81, 0xbd,
        'a' as u8,
    ];
    let hay = str::from_utf8(&hay).unwrap();
    let reg = Regex::new("\\A(\\p{HandakuonHiragana}{5})\\p{^HandakuonHiragana}\\z").unwrap();

    match reg.captures(hay) {
        Some(caps) => {
            println!("match at {}", caps.offset());
            for (i, cap) in caps.iter_pos().enumerate() {
                match cap {
                    Some(pos) => println!("{}: {:?}", i, pos),
                    None => println!("{}: did not capture", i),
                }
            }
        }
        None => println!("search fail"),
    }
}