wasmgdb_ddbug_parser/
source.rs1use crate::unit::Unit;
2
3#[derive(Debug, Default, Clone)]
5pub struct Source<'input> {
6 pub(crate) directory: Option<&'input str>,
7 pub(crate) file: Option<&'input str>,
8 pub(crate) line: u32,
9 pub(crate) column: u32,
10}
11
12impl<'input> Source<'input> {
13 #[inline]
17 pub fn directory(&self) -> Option<&str> {
18 self.directory
19 }
20
21 #[inline]
23 pub fn file(&self) -> Option<&str> {
24 self.file
25 }
26
27 #[inline]
29 pub fn is_none(&self) -> bool {
30 self.file.is_none()
31 }
32
33 #[inline]
35 pub fn is_some(&self) -> bool {
36 self.file.is_some()
37 }
38
39 pub fn path(&self, unit: &Unit) -> Option<String> {
41 fn is_absolute(directory: &str) -> bool {
42 directory.get(0..1) == Some("/") || directory.get(1..2) == Some(":")
43 }
44
45 self.file().map(|file| {
46 let mut path = String::new();
47 if let Some(directory) = self.directory() {
48 if let (false, Some(unit_dir)) = (is_absolute(directory), unit.dir()) {
49 path.push_str(unit_dir);
50 if !unit_dir.ends_with('/') {
51 path.push('/');
52 }
53 }
54 path.push_str(directory);
55 if !directory.ends_with('/') {
56 path.push('/');
57 }
58 }
59 path.push_str(file);
60 path
61 })
62 }
63
64 #[inline]
68 pub fn line(&self) -> u32 {
69 self.line
70 }
71
72 #[inline]
76 pub fn column(&self) -> u32 {
77 self.column
78 }
79}