public Shabdkosh_UnitTest1() { //arrange fileRepository = new TextFileRepository(); textOperation = new TextOperation(); shabdkoshService = new ShabdkoshService(fileRepository, textOperation); }
public ShabdkoshService(ITextFileRepository fileRepository, ITextOperation textOperation) { _textOperation = textOperation; string text = fileRepository.ReadTextFile(); occuranceOfAWord = _textOperation.Text2DictWordOccurance(text); }
/// <summary> /// /// </summary> public TextEditDocumentItem(CharacterLocation location, ITextOperation operation, EmbeddedInstructionOrigin embeddedInstructionOrigin, IEnumerable <ITokenOption> tagCreationOptions) : base(location, tagCreationOptions) { Operation = operation ?? throw new ArgumentNullException(nameof(operation)); EmbeddedInstructionOrigin = embeddedInstructionOrigin; }
/// <summary>Try to apply a text operation.</summary> /// <param name="target">The target map to change.</param> /// <param name="operation">The text operation to apply.</param> /// <param name="error">An error indicating why applying the operation failed, if applicable.</param> /// <returns>Returns whether applying the operation succeeded.</returns> private bool TryApplyTextOperation(Map target, ITextOperation operation, [NotNullWhen(false)] out string?error) { var targetRoot = operation.GetTargetRoot(); switch (targetRoot) { case TextOperationTargetRoot.MapProperties: { // validate if (operation.Target.Length > 2) { return(this.Fail($"a '{TextOperationTargetRoot.MapProperties}' path must only have one other segment for the property name.", out error)); } // get key/value string key = operation.Target[1].Value !; string?value = target.Properties.TryGetValue(key, out PropertyValue? property) ? property.ToString() : null; // apply target.Properties[key] = operation.Apply(value); } break; default: return(this.Fail( targetRoot == null ? $"unknown path root '{operation.Target[0]}'." : $"path root '{targetRoot}' isn't valid for an {nameof(PatchType.EditMap)} patch", out error )); } error = null; return(true); }
/// <inheritdoc /> protected override void DeSerializeXml(XmlReader reader) { base.DeSerializeXml(reader); reader.ReadStartElement(); //<TextOperation> AssertElement(reader, "TextOperation"); var attribute = reader.GetAttribute(nameof(ITextOperation.TextOperationType)); switch (attribute) { case "LineBreak": Operation = new AppendLineBreakTextOperation(); break; case "TrimLineBreaks": Operation = new TrimLineBreakTextOperation(); break; default: throw new InvalidOperationException($"The TextOperation '{attribute}' is invalid"); } Operation.ReadXml(reader); reader.ReadEndElement(); //</TextOperation> }
/// <summary> /// Adds a new <see cref="TextEditDocumentItem"/> /// </summary> public static MorestachioDocumentFluentApi AddTextModification(this MorestachioDocumentFluentApi api, ITextOperation textOperation) { return(api.AddChild(builder => new TextEditDocumentItem(textOperation))); }
public void Do(ITextOperation operation) { operation.Do(); UndoStack.Push(operation); RedoStack.Clear(); }
public FindDefinitionByKeywordHandler(ITextFileRepository fileRepository, ITextOperation textOperation) { this.fileRepository = fileRepository ?? throw new ArgumentNullException(nameof(fileRepository)); this._textOperation = textOperation ?? throw new ArgumentNullException(nameof(textOperation)); }
/// <summary> /// Adds a new <see cref="TextEditDocumentItem"/> /// </summary> public static MorestachioDocumentFluentApi AddTextModification(this MorestachioDocumentFluentApi api, ITextOperation textOperation) { return(api.AddChild(builder => new TextEditDocumentItem(CharacterLocation.Unknown, textOperation, EmbeddedInstructionOrigin.Self, Enumerable.Empty <ITokenOption>()))); }
/// <summary> /// /// </summary> /// <param name="operation"></param> public TextEditDocumentItem([NotNull] ITextOperation operation) { Operation = operation ?? throw new ArgumentNullException(nameof(operation)); }