Skip to content

Commit 03bce03

Browse files
davidmhewittbilelmoussaoui
authored andcommitted
glib: Implement Regex
These modules are inefficient and should not be used by Rust programs except for compatibility with GLib.Regex based APIs. All methods are implemented except for g_regex_replace_eval
1 parent 203c957 commit 03bce03

File tree

8 files changed

+767
-0
lines changed

8 files changed

+767
-0
lines changed

glib/Gir.toml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ generate = [
2727
"GLib.NormalizeMode",
2828
"GLib.OptionArg",
2929
"GLib.OptionFlags",
30+
"GLib.RegexCompileFlags",
31+
"GLib.RegexMatchFlags",
3032
"GLib.SeekType",
3133
"GLib.SpawnFlags",
3234
"GLib.Time",
@@ -714,6 +716,84 @@ status = "generate"
714716
name = "get_user_data"
715717
ignore = true # unsafe pointer
716718

719+
[[object]]
720+
name = "GLib.MatchInfo"
721+
status = "generate"
722+
[[object.function]]
723+
name = "expand_references"
724+
# impl IntoGStr for parameters instead of &str
725+
manual = true
726+
[[object.function]]
727+
name = "fetch_named"
728+
# impl IntoGStr for parameters instead of &str
729+
manual = true
730+
[[object.function]]
731+
name = "fetch_named_pos"
732+
# impl IntoGStr for parameters instead of &str
733+
manual = true
734+
735+
[[object]]
736+
name = "GLib.Regex"
737+
status = "generate"
738+
[[object.function]]
739+
name = "check_replacement"
740+
# impl IntoGStr for parameters instead of &str
741+
manual = true
742+
[[object.function]]
743+
name = "escape_nul"
744+
# impl IntoGStr for parameters instead of &str
745+
manual = true
746+
[[object.function]]
747+
name = "escape_string"
748+
# impl IntoGStr for parameters instead of &str
749+
manual = true
750+
[[object.function]]
751+
name = "match"
752+
# implement in terms of match_full
753+
manual = true
754+
[[object.function]]
755+
name = "match_all"
756+
# implement in terms of match_all_full
757+
manual = true
758+
[[object.function]]
759+
name = "match_all_full"
760+
# impl IntoGStr for parameters instead of &str
761+
manual = true
762+
[[object.function]]
763+
name = "match_simple"
764+
# impl IntoGStr for parameters instead of &str
765+
manual = true
766+
[[object.function]]
767+
name = "match_full"
768+
# impl IntoGStr for parameters instead of &str
769+
manual = true
770+
[[object.function]]
771+
name = "replace"
772+
# impl IntoGStr for parameters instead of &str
773+
manual = true
774+
[[object.function]]
775+
name = "replace_literal"
776+
# impl IntoGStr for parameters instead of &str
777+
manual = true
778+
[[object.function]]
779+
name = "split"
780+
# implement in terms of split_full
781+
manual = true
782+
[[object.function]]
783+
name = "split_full"
784+
# impl IntoGStr for parameters instead of &str
785+
# return slice of str pointers
786+
manual = true
787+
[[object.function]]
788+
name = "split_simple"
789+
# impl IntoGStr for parameters instead of &str
790+
# return slice of str pointers
791+
manual = true
792+
[[object.function]]
793+
name = "get_string_number"
794+
# impl IntoGStr for parameters instead of &str
795+
manual = true
796+
717797
[[object]]
718798
name = "GLib.Source"
719799
status = "generate"

glib/src/auto/flags.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,126 @@ impl FromGlib<ffi::GOptionFlags> for OptionFlags {
362362
}
363363
}
364364

365+
bitflags! {
366+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
367+
#[doc(alias = "GRegexCompileFlags")]
368+
pub struct RegexCompileFlags: u32 {
369+
#[doc(alias = "G_REGEX_DEFAULT")]
370+
const DEFAULT = ffi::G_REGEX_DEFAULT as _;
371+
#[doc(alias = "G_REGEX_CASELESS")]
372+
const CASELESS = ffi::G_REGEX_CASELESS as _;
373+
#[doc(alias = "G_REGEX_MULTILINE")]
374+
const MULTILINE = ffi::G_REGEX_MULTILINE as _;
375+
#[doc(alias = "G_REGEX_DOTALL")]
376+
const DOTALL = ffi::G_REGEX_DOTALL as _;
377+
#[doc(alias = "G_REGEX_EXTENDED")]
378+
const EXTENDED = ffi::G_REGEX_EXTENDED as _;
379+
#[doc(alias = "G_REGEX_ANCHORED")]
380+
const ANCHORED = ffi::G_REGEX_ANCHORED as _;
381+
#[doc(alias = "G_REGEX_DOLLAR_ENDONLY")]
382+
const DOLLAR_ENDONLY = ffi::G_REGEX_DOLLAR_ENDONLY as _;
383+
#[doc(alias = "G_REGEX_UNGREEDY")]
384+
const UNGREEDY = ffi::G_REGEX_UNGREEDY as _;
385+
#[doc(alias = "G_REGEX_RAW")]
386+
const RAW = ffi::G_REGEX_RAW as _;
387+
#[doc(alias = "G_REGEX_NO_AUTO_CAPTURE")]
388+
const NO_AUTO_CAPTURE = ffi::G_REGEX_NO_AUTO_CAPTURE as _;
389+
#[doc(alias = "G_REGEX_OPTIMIZE")]
390+
const OPTIMIZE = ffi::G_REGEX_OPTIMIZE as _;
391+
#[doc(alias = "G_REGEX_FIRSTLINE")]
392+
const FIRSTLINE = ffi::G_REGEX_FIRSTLINE as _;
393+
#[doc(alias = "G_REGEX_DUPNAMES")]
394+
const DUPNAMES = ffi::G_REGEX_DUPNAMES as _;
395+
#[doc(alias = "G_REGEX_NEWLINE_CR")]
396+
const NEWLINE_CR = ffi::G_REGEX_NEWLINE_CR as _;
397+
#[doc(alias = "G_REGEX_NEWLINE_LF")]
398+
const NEWLINE_LF = ffi::G_REGEX_NEWLINE_LF as _;
399+
#[doc(alias = "G_REGEX_NEWLINE_CRLF")]
400+
const NEWLINE_CRLF = ffi::G_REGEX_NEWLINE_CRLF as _;
401+
#[doc(alias = "G_REGEX_NEWLINE_ANYCRLF")]
402+
const NEWLINE_ANYCRLF = ffi::G_REGEX_NEWLINE_ANYCRLF as _;
403+
#[doc(alias = "G_REGEX_BSR_ANYCRLF")]
404+
const BSR_ANYCRLF = ffi::G_REGEX_BSR_ANYCRLF as _;
405+
#[doc(alias = "G_REGEX_JAVASCRIPT_COMPAT")]
406+
const JAVASCRIPT_COMPAT = ffi::G_REGEX_JAVASCRIPT_COMPAT as _;
407+
}
408+
}
409+
410+
#[doc(hidden)]
411+
impl IntoGlib for RegexCompileFlags {
412+
type GlibType = ffi::GRegexCompileFlags;
413+
414+
#[inline]
415+
fn into_glib(self) -> ffi::GRegexCompileFlags {
416+
self.bits()
417+
}
418+
}
419+
420+
#[doc(hidden)]
421+
impl FromGlib<ffi::GRegexCompileFlags> for RegexCompileFlags {
422+
#[inline]
423+
unsafe fn from_glib(value: ffi::GRegexCompileFlags) -> Self {
424+
Self::from_bits_truncate(value)
425+
}
426+
}
427+
428+
bitflags! {
429+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
430+
#[doc(alias = "GRegexMatchFlags")]
431+
pub struct RegexMatchFlags: u32 {
432+
#[doc(alias = "G_REGEX_MATCH_DEFAULT")]
433+
const DEFAULT = ffi::G_REGEX_MATCH_DEFAULT as _;
434+
#[doc(alias = "G_REGEX_MATCH_ANCHORED")]
435+
const ANCHORED = ffi::G_REGEX_MATCH_ANCHORED as _;
436+
#[doc(alias = "G_REGEX_MATCH_NOTBOL")]
437+
const NOTBOL = ffi::G_REGEX_MATCH_NOTBOL as _;
438+
#[doc(alias = "G_REGEX_MATCH_NOTEOL")]
439+
const NOTEOL = ffi::G_REGEX_MATCH_NOTEOL as _;
440+
#[doc(alias = "G_REGEX_MATCH_NOTEMPTY")]
441+
const NOTEMPTY = ffi::G_REGEX_MATCH_NOTEMPTY as _;
442+
#[doc(alias = "G_REGEX_MATCH_PARTIAL")]
443+
const PARTIAL = ffi::G_REGEX_MATCH_PARTIAL as _;
444+
#[doc(alias = "G_REGEX_MATCH_NEWLINE_CR")]
445+
const NEWLINE_CR = ffi::G_REGEX_MATCH_NEWLINE_CR as _;
446+
#[doc(alias = "G_REGEX_MATCH_NEWLINE_LF")]
447+
const NEWLINE_LF = ffi::G_REGEX_MATCH_NEWLINE_LF as _;
448+
#[doc(alias = "G_REGEX_MATCH_NEWLINE_CRLF")]
449+
const NEWLINE_CRLF = ffi::G_REGEX_MATCH_NEWLINE_CRLF as _;
450+
#[doc(alias = "G_REGEX_MATCH_NEWLINE_ANY")]
451+
const NEWLINE_ANY = ffi::G_REGEX_MATCH_NEWLINE_ANY as _;
452+
#[doc(alias = "G_REGEX_MATCH_NEWLINE_ANYCRLF")]
453+
const NEWLINE_ANYCRLF = ffi::G_REGEX_MATCH_NEWLINE_ANYCRLF as _;
454+
#[doc(alias = "G_REGEX_MATCH_BSR_ANYCRLF")]
455+
const BSR_ANYCRLF = ffi::G_REGEX_MATCH_BSR_ANYCRLF as _;
456+
#[doc(alias = "G_REGEX_MATCH_BSR_ANY")]
457+
const BSR_ANY = ffi::G_REGEX_MATCH_BSR_ANY as _;
458+
#[doc(alias = "G_REGEX_MATCH_PARTIAL_SOFT")]
459+
const PARTIAL_SOFT = ffi::G_REGEX_MATCH_PARTIAL_SOFT as _;
460+
#[doc(alias = "G_REGEX_MATCH_PARTIAL_HARD")]
461+
const PARTIAL_HARD = ffi::G_REGEX_MATCH_PARTIAL_HARD as _;
462+
#[doc(alias = "G_REGEX_MATCH_NOTEMPTY_ATSTART")]
463+
const NOTEMPTY_ATSTART = ffi::G_REGEX_MATCH_NOTEMPTY_ATSTART as _;
464+
}
465+
}
466+
467+
#[doc(hidden)]
468+
impl IntoGlib for RegexMatchFlags {
469+
type GlibType = ffi::GRegexMatchFlags;
470+
471+
#[inline]
472+
fn into_glib(self) -> ffi::GRegexMatchFlags {
473+
self.bits()
474+
}
475+
}
476+
477+
#[doc(hidden)]
478+
impl FromGlib<ffi::GRegexMatchFlags> for RegexMatchFlags {
479+
#[inline]
480+
unsafe fn from_glib(value: ffi::GRegexMatchFlags) -> Self {
481+
Self::from_bits_truncate(value)
482+
}
483+
}
484+
365485
bitflags! {
366486
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
367487
#[doc(alias = "GSpawnFlags")]

glib/src/auto/match_info.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This file was generated by gir (https://github.com/gtk-rs/gir)
2+
// from gir-files (https://github.com/gtk-rs/gir-files)
3+
// DO NOT EDIT
4+
5+
use crate::{translate::*, Error, Regex};
6+
7+
crate::wrapper! {
8+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9+
pub struct MatchInfo(Shared<ffi::GMatchInfo>);
10+
11+
match fn {
12+
ref => |ptr| ffi::g_match_info_ref(ptr),
13+
unref => |ptr| ffi::g_match_info_unref(ptr),
14+
type_ => || ffi::g_match_info_get_type(),
15+
}
16+
}
17+
18+
impl MatchInfo {
19+
#[doc(alias = "g_match_info_fetch")]
20+
pub fn fetch(&self, match_num: i32) -> Option<crate::GString> {
21+
unsafe { from_glib_full(ffi::g_match_info_fetch(self.to_glib_none().0, match_num)) }
22+
}
23+
24+
#[doc(alias = "g_match_info_fetch_all")]
25+
pub fn fetch_all(&self) -> Vec<crate::GString> {
26+
unsafe {
27+
FromGlibPtrContainer::from_glib_full(ffi::g_match_info_fetch_all(self.to_glib_none().0))
28+
}
29+
}
30+
31+
#[doc(alias = "g_match_info_fetch_pos")]
32+
pub fn fetch_pos(&self, match_num: i32) -> Option<(i32, i32)> {
33+
unsafe {
34+
let mut start_pos = std::mem::MaybeUninit::uninit();
35+
let mut end_pos = std::mem::MaybeUninit::uninit();
36+
let ret = from_glib(ffi::g_match_info_fetch_pos(
37+
self.to_glib_none().0,
38+
match_num,
39+
start_pos.as_mut_ptr(),
40+
end_pos.as_mut_ptr(),
41+
));
42+
if ret {
43+
Some((start_pos.assume_init(), end_pos.assume_init()))
44+
} else {
45+
None
46+
}
47+
}
48+
}
49+
50+
#[doc(alias = "g_match_info_get_match_count")]
51+
#[doc(alias = "get_match_count")]
52+
pub fn match_count(&self) -> i32 {
53+
unsafe { ffi::g_match_info_get_match_count(self.to_glib_none().0) }
54+
}
55+
56+
#[doc(alias = "g_match_info_get_regex")]
57+
#[doc(alias = "get_regex")]
58+
pub fn regex(&self) -> Regex {
59+
unsafe { from_glib_none(ffi::g_match_info_get_regex(self.to_glib_none().0)) }
60+
}
61+
62+
#[doc(alias = "g_match_info_get_string")]
63+
#[doc(alias = "get_string")]
64+
pub fn string(&self) -> crate::GString {
65+
unsafe { from_glib_none(ffi::g_match_info_get_string(self.to_glib_none().0)) }
66+
}
67+
68+
#[doc(alias = "g_match_info_is_partial_match")]
69+
pub fn is_partial_match(&self) -> bool {
70+
unsafe { from_glib(ffi::g_match_info_is_partial_match(self.to_glib_none().0)) }
71+
}
72+
73+
#[doc(alias = "g_match_info_matches")]
74+
pub fn matches(&self) -> bool {
75+
unsafe { from_glib(ffi::g_match_info_matches(self.to_glib_none().0)) }
76+
}
77+
78+
#[doc(alias = "g_match_info_next")]
79+
pub fn next(&self) -> Result<(), crate::Error> {
80+
unsafe {
81+
let mut error = std::ptr::null_mut();
82+
let is_ok = ffi::g_match_info_next(self.to_glib_none().0, &mut error);
83+
debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
84+
if error.is_null() {
85+
Ok(())
86+
} else {
87+
Err(from_glib_full(error))
88+
}
89+
}
90+
}
91+
}

glib/src/auto/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pub use self::main_loop::MainLoop;
2020
mod markup_parse_context;
2121
pub use self::markup_parse_context::MarkupParseContext;
2222

23+
mod match_info;
24+
pub use self::match_info::MatchInfo;
25+
26+
mod regex;
27+
pub use self::regex::Regex;
28+
2329
mod source;
2430
pub use self::source::Source;
2531

@@ -67,6 +73,8 @@ pub use self::flags::LogLevelFlags;
6773
#[cfg_attr(docsrs, doc(cfg(feature = "v2_72")))]
6874
pub use self::flags::MainContextFlags;
6975
pub use self::flags::OptionFlags;
76+
pub use self::flags::RegexCompileFlags;
77+
pub use self::flags::RegexMatchFlags;
7078
pub use self::flags::SpawnFlags;
7179
#[cfg(feature = "v2_66")]
7280
#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]

0 commit comments

Comments
 (0)