/// <summary> /// Reads a StringId from a string representation /// </summary> public override StringId ReadStringId() { Start <StringId>(); var isValid = ReadBoolean(); var value = isValid ? m_stringTable.AddString(ReadString()) : StringId.Invalid; End(); return(value); }
/// <summary> /// Try to create a PathAtom from a string. /// </summary> /// <remarks> /// The rules for a valid path atom are that the input string may not /// be empty and must only contain characters reported as valid by IsValidPathAtomChar. /// </remarks> public static ParseResult TryCreate <T>(StringTable table, T atom, out PathAtom result, out int characterWithError) where T : struct, ICharSpan <T> { Contract.RequiresNotNull(table); ParseResult validationResult = Validate(atom, out characterWithError); result = validationResult == ParseResult.Success ? new PathAtom(table.AddString(atom)) : default(PathAtom); return(validationResult); }
/// <summary> /// Creates an IdentifierAtom from a string regardless whether it is a well-formed identifier atom. /// </summary> /// <remarks> /// This is useful for hard-coded atoms, don't use with any user input. /// </remarks> public static SymbolAtom CreateUnchecked <T>(StringTable table, T atom) where T : struct, ICharSpan <T> { Contract.RequiresNotNull(table); Contract.Requires(atom.Length > 0); StringId id = table.AddString(atom); return(new SymbolAtom(id)); }
/// <summary> /// Creates an IdentifierAtom from a string regardless whether it is a well-formed identifier atom. /// </summary> /// <remarks> /// This is useful for hard-coded atoms, don't use with any user input. /// </remarks> public static SymbolAtom CreateUnchecked <T>(StringTable table, T atom) where T : struct, ICharSpan <T> { Contract.Requires(table != null); Contract.Requires(atom.Length > 0); Contract.Ensures(Contract.Result <SymbolAtom>().IsValid); StringId id = table.AddString(atom); return(new SymbolAtom(id)); }
/// <summary> /// Try to create an IdentifierAtom from a string. /// </summary> /// <remarks> /// The rules for a valid identifier atom are that the input string may not /// be empty and must only contain characters reported as valid by IsValidIdentifierAtomChar. /// </remarks> public static ParseResult TryCreate <T>(StringTable table, T atom, out SymbolAtom result, out int characterWithError) where T : struct, ICharSpan <T> { Contract.Requires(table != null); //Contract.Ensures((Contract.Result<ParseResult>() == ParseResult.Success) == Contract.ValueAtReturn(out result).IsValid); ParseResult validationResult = Validate(atom, out characterWithError); result = validationResult == ParseResult.Success ? new SymbolAtom(table.AddString(atom)) : default(SymbolAtom); return(validationResult); }
/// <summary> /// Imports the given path table into the current path table and returns /// a mapping from the other path table ids to the current path table's absolute paths /// </summary> public AbsolutePath[] Import(PathTable otherTable) { var importedPathIndex = new AbsolutePath[otherTable.Count]; var nameBuffer = new char[1024]; for (int i = 1; i < otherTable.Count; i++) { var otherChildPath = new AbsolutePath(i); var otherParent = otherChildPath.GetParent(otherTable); // The contract here is the parent's id is always smaller than its child's id. // Thus, importPathIndex below is properly initialized. var importedParent = importedPathIndex[otherParent.Value.Index]; var otherChildName = otherChildPath.GetName(otherTable); int length = otherTable.StringTable.CopyString(otherChildName.StringId, ref nameBuffer, 0, allowResizeBuffer: true); var component = StringTable.AddString(new CharArraySegment(nameBuffer, 0, length)); var child = AddComponent(importedParent.Value, component); importedPathIndex[i] = new AbsolutePath(child); } return(importedPathIndex); }
/// <summary> /// Creates a new string ID. /// </summary> public static StringId Create(StringTable table, string value) { return(table.AddString(value)); }