summaryrefslogtreecommitdiff
path: root/engine/src/file_format/wavefront/common.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/file_format/wavefront/common.rs')
-rw-r--r--engine/src/file_format/wavefront/common.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/engine/src/file_format/wavefront/common.rs b/engine/src/file_format/wavefront/common.rs
index 0c5ac33..2e27bcb 100644
--- a/engine/src/file_format/wavefront/common.rs
+++ b/engine/src/file_format/wavefront/common.rs
@@ -218,11 +218,19 @@ impl Value
})?));
}
- if value.contains('/') {
+ if value.contains('/')
+ && value
+ .chars()
+ .all(|character| character.is_ascii_digit() || character == '/')
+ {
return Ok(Self::Triplet(Triplet::parse::<KeywordT>(value, line_no)?));
}
- if value.contains(|character: char| character.is_ascii_digit()) {
+ if !value.is_empty()
+ && value
+ .chars()
+ .all(|character: char| character.is_ascii_digit())
+ {
return Ok(Self::Integer(value.parse().map_err(|err| {
ParsingError::InvalidIntegerValue {
err,
@@ -238,6 +246,18 @@ impl Value
Err(ParsingError::UnknownValueType(value.to_string()))
}
+
+ pub fn to_text(
+ &self,
+ argument_index: usize,
+ line_no: usize,
+ ) -> Result<&str, ParsingError>
+ {
+ match self {
+ Value::Text(value) => Ok(value),
+ _ => Err(ParsingError::UnexpectedArgumentType { argument_index, line_no }),
+ }
+ }
}
#[derive(Debug)]
@@ -265,6 +285,22 @@ impl<KeywordT: Keyword> Statement<KeywordT>
}
}
+ pub fn get_text_arg(&self, index: usize, line_no: usize)
+ -> Result<&str, ParsingError>
+ {
+ match self.arguments.get(index) {
+ Some(Value::Text(value)) => Ok(value),
+ Some(_) => Err(ParsingError::UnexpectedArgumentType {
+ argument_index: index,
+ line_no,
+ }),
+ None => Err(ParsingError::MissingArgument {
+ keyword: self.keyword.to_string(),
+ line_no,
+ }),
+ }
+ }
+
pub fn get_triplet_arg(
&self,
index: usize,