need an "InsertEvaluator" function

paultraite

New member
Joined
Feb 7, 2006
Messages
1
I have an annotated string:
ref class AnnotatedStr
{
public:
String ^str; // the basic char data
// there is one entry in each of the following for each char in str
array<int>^ font;
array<int>^ color;
array<int>^ pointsize;
}

I need to use Regex.Replace() on the string.
ex. Replace( MyAnnotatedString->str, "(?<ugg>[A-Z]{3,6}))",
"Insert1 ${ugg} insert2", MyMatchEvaluator )

Problem -- The inserted text will then be mis-aligned with my annotated arrays of extra data.

1. I didnt see anything to support this in Replace().
2. I thought about deriving from String, and overriding some function there, but didnt find anything promising nor knew what functions Replace() might use that I should override.

Anyone got any clues here?
 
When doing this type of thing I typically do an optional leading match on whitespace and then add it to whatever line Im replicating. This will make it so that each replicated line is indented to the exact same level as the line you matched on.
 
I think that your best bet would be to first use regex to find the matches that would be replaced in order to identify offsets and lengths, and use that data to modify the relevant annotation data before actually performing the replacement.

BTW, that is a lot of data per character (right now you are looking at 14 bytes per char).

Depending on your needs, the scale of the project, and how much effort you are willing to put into it, you might want to consider putting the formatting data inline in the string (html-esque). Not only will this (with some dilligence in your coding) not cause problems with misaligned data, but allow you to specify changes in formatting instead of formatting per char.
 
Back
Top