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
use std::ffi::c_char;

use pkgcraft::dep::parse;

use crate::macros::*;
use crate::panic::ffi_catch_panic;

/// Verify a package category name is valid.
///
/// Returns NULL on error.
///
/// # Safety
/// The argument be a valid UTF-8 string.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_parse_category(s: *const c_char) -> *const c_char {
    ffi_catch_panic! {
        let val = try_str_from_ptr!(s);
        unwrap_or_panic!(parse::category(val));
        s
    }
}

/// Verify a package name is valid.
///
/// Returns NULL on error.
///
/// # Safety
/// The argument be a valid UTF-8 string.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_parse_package(s: *const c_char) -> *const c_char {
    ffi_catch_panic! {
        let val = try_str_from_ptr!(s);
        unwrap_or_panic!(parse::package(val));
        s
    }
}

/// Verify a repository name is valid.
///
/// Returns NULL on error.
///
/// # Safety
/// The argument be a valid UTF-8 string.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_parse_repo(s: *const c_char) -> *const c_char {
    ffi_catch_panic! {
        let val = try_str_from_ptr!(s);
        unwrap_or_panic!(parse::repo(val));
        s
    }
}

/// Verify a package USE flag name is valid.
///
/// Returns NULL on error.
///
/// # Safety
/// The argument be a valid UTF-8 string.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_parse_use_flag(s: *const c_char) -> *const c_char {
    ffi_catch_panic! {
        let val = try_str_from_ptr!(s);
        unwrap_or_panic!(parse::use_flag(val));
        s
    }
}