Commit a6b8e16b authored by qinsoon's avatar qinsoon

removing preceding AT or PERCENTAGE in MuName

Client may pass a name with AT or PERCENTAGE, but internally MuName
does not contain that.
parent f8fbee3d
......@@ -804,8 +804,8 @@ impl fmt::Display for MemoryLocation {
#[repr(C)]
#[derive(Debug)] // Display, PartialEq, Clone
pub struct MuEntityHeader {
pub id: MuID,
pub name: RwLock<Option<MuName>>
id: MuID,
name: RwLock<Option<MuName>>
}
impl Clone for MuEntityHeader {
......@@ -856,7 +856,7 @@ impl MuEntityHeader {
pub fn named(id: MuID, name: MuName) -> MuEntityHeader {
MuEntityHeader {
id: id,
name: RwLock::new(Some(name))
name: RwLock::new(Some(MuEntityHeader::name_check(name)))
}
}
......@@ -867,6 +867,21 @@ impl MuEntityHeader {
pub fn name(&self) -> Option<MuName> {
self.name.read().unwrap().clone()
}
pub fn set_name(&self, name: MuName) {
let mut name_guard = self.name.write().unwrap();
*name_guard = Some(MuEntityHeader::name_check(name));
}
fn name_check(name: MuName) -> MuName {
if name.starts_with("@") || name.starts_with("%") {
let (_, name) = name.split_at(1);
return name.to_string();
}
name
}
}
impl PartialEq for MuEntityHeader {
......
......@@ -11,12 +11,11 @@ macro_rules! impl_mu_entity {
($entity: ty) => {
impl MuEntity for $entity {
#[inline(always)]
fn id(&self) -> MuID {self.hdr.id}
fn id(&self) -> MuID {self.hdr.id()}
#[inline(always)]
fn name(&self) -> Option<MuName> {self.hdr.name()}
fn set_name(&self, name: MuName) {
let mut write_guard = self.hdr.name.write().unwrap();
*write_guard = Some(name);
self.hdr.set_name(name);
}
fn as_entity(&self) -> &MuEntity {
let ref_ty : &$entity = self;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment