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
use crate::{
    containers::{ptr::UnPtr, Ptr},
    Bytes, Token,
};

/// Representation of the value of the string literal
///
/// In Ruby string literals don't have to be valid in their encoding.
/// Because of that we don't even try to convert them into string.
/// Instead, they are emitted as byte arrays that (if you want)
/// can be converted to a string.
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct StringValue {
    /// Byte array, can be converted to a string
    pub bytes: Bytes,
}

impl StringValue {
    pub(crate) fn new(token: Ptr<Token>) -> Self {
        Self {
            bytes: token.unptr().token_value,
        }
    }

    pub(crate) fn empty() -> Self {
        Self {
            bytes: Bytes::empty(),
        }
    }
}