Re: [Fire-commits] fire MessageItem.m,1.52,1.53
Graham Booker <[email protected]> Sun, 27 Jun 2004 21:42:31 -0500
| Newsgroups | gmane.network.fire.devel |
|---|---|
| Message-ID | <[email protected]> |
Uhh..... There are a few things wrong here that I see... Also, these should likely be added a new state in the FSM. Comments below: On Jun 27, 2004, at 8:57 PM, [email protected] wrote: > Update of /cvsroot/fire/fire > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24286 > > Modified Files: > MessageItem.m > Log Message: > Smart markup > > Index: MessageItem.m > =================================================================== > RCS file: /cvsroot/fire/fire/MessageItem.m,v > retrieving revision 1.52 > retrieving revision 1.53 > diff -C2 -d -r1.52 -r1.53 > *** MessageItem.m 26 Jun 2004 05:00:33 -0000 1.52 > --- MessageItem.m 28 Jun 2004 01:57:17 -0000 1.53 > *************** > *** 49,52 **** > --- 49,53 ---- > > #import "PluginController.h" > + #import <AGRegex/AGRegex.h> > > // State machine controls > *************** > *** 464,467 **** > --- 465,469 ---- > NSMutableAttributedString *tmpAtrString = nil; > MessageItem *newMessage = nil; > + AGRegex* re = nil; > unichar ch; > int i; > *************** > *** 472,475 **** > --- 474,478 ---- > BOOL canSend; > BOOL firstMessage = NO; > + BOOL prestrippedFonts = NO; > > while (continueProcessing) { > *************** > *** 738,743 **** > --- 741,759 ---- > > case MIS_SERVICE_ATTR_DECODE: > + // Incoming, this works here. Check for outgoing support. > + if ( [[NSUserDefaults standardUserDefaults] > boolForKey:@"UseSmartMarkup"] ) { > + re = [AGRegex regexWithPattern:@"\\*([^\\*]+)\\*" options:( > AGRegexCaseInsensitive | AGRegexDotAll )]; > + [self setMessageString:[re replaceWithString:@"<b>$1</b>" > inString:[self messageString]]]; > + re = [AGRegex regexWithPattern:@"_([^_]+)_" options:( > AGRegexCaseInsensitive | AGRegexDotAll )]; > + [self setMessageString:[re replaceWithString:@"<i>$1</i>" > inString:[self messageString]]]; > + } This is assuming a service that supports <i> and <b> tags. Not all of them do, so the others will have screwing things. Why not just run this on [attributedSting string] after the next line, and change the attributedString's attributes at those ranges using enumerators, (like you did in MIS_SERVICE_ATTR_ENCODE)? > [self setAttributedMessage:[[[[account service] > decodeMessageAttributes:self] mutableCopy] autorelease]]; > // From here on we use attributedString > + if([defaults boolForKey:DISABLE_INCOMING_FONTS]) { > + re = [AGRegex regexWithPattern:@"(face|ABSZ|size)=\"[^\"]+\"" > options:( AGRegexCaseInsensitive | AGRegexDotAll )]; > + [self setMessageString:[re replaceWithString:@"" > inString:messageString]]; > + prestrippedFonts = YES; > + } > + //NSLog(messageString); This is modifying the messageString after it has been already converted to an attributed string. Again, assuming a service using certain tags. Why do this, what is wrong with striping later as done below? That ensures it works on all services. > NEXT_STATE_FALLTHROUGH; > > *************** > *** 805,814 **** > if (((!outbound) && ([defaults > boolForKey:DISABLE_INCOMING_FONTS])) || > (messageType == MI_SERVICE_MESSAGE)) { > > ! [attributedString > removeAttribute:NSFontAttributeName > ! > range:NSMakeRange(0,[attributedString length])]; > ! [attributedString > addAttribute:NSFontAttributeName > ! value:[[MainController > mainController] incomingMessageFont] > ! > range:NSMakeRange(0,[attributedString length])]; > } > > --- 821,833 ---- > if (((!outbound) && ([defaults > boolForKey:DISABLE_INCOMING_FONTS])) || > (messageType == MI_SERVICE_MESSAGE)) { > + > + if (!prestrippedFonts) { > > ! [attributedString removeAttribute:NSFontAttributeName > ! range:NSMakeRange(0,[attributedString length])]; > ! [attributedString addAttribute:NSFontAttributeName > ! value:[[MainController mainController] > incomingMessageFont] > ! range:NSMakeRange(0,[attributedString length])]; > ! } > } > > *************** > *** 1029,1033 **** > --- 1048,1071 ---- > > case MIS_SERVICE_ATTR_ENCODE: > + if ([defaults boolForKey:@"UseSmartMarkup"]) { > + re = [AGRegex regexWithPattern:@"\\*([^\\*]+)\\*" options:( > AGRegexCaseInsensitive | AGRegexDotAll )]; > + NSEnumerator* matches = [re > findEnumeratorInString:[attributedString string]]; > + AGRegexMatch *m = nil; > + while (m = [matches nextObject]) { > + NSString* gp = [m group]; > + NSRange r = [m range]; > + NSLog(@" - \"%@\" (%d,%d)",gp,r.location,r.length); > + > + // FIXME (later) -- I assume here that the font doesn't change > over the course of the range > + NSFont* currFont = [attributedString > attribute:NSFontAttributeName atIndex:r.location effectiveRange:nil]; > + NSFont* newBoldFont = [[NSFontManager sharedFontManager] > convertFont:currFont toHaveTrait:NSBoldFontMask]; > + [attributedString addAttribute:NSFontAttributeName > value:newBoldFont range:r]; > + [attributedString > deleteCharactersInRange:NSMakeRange(r.location+r.length-1,1)]; > + [attributedString > deleteCharactersInRange:NSMakeRange(r.location,1)]; > + } > + } did you forget the _([^_]+)_ here? > + > [self setMessageString:[[account service] > encodeMessageAttributes:self]]; > + > // Starting Here we use messageString > NEXT_STATE_FALLTHROUGH; ------------------------------------------------------------------ Graham Booker Texas A&M University [email protected] Graduate Student in ELEN ------------------------------------------------------------------
smime.p7s
(application/pkcs7-signature, 2.3 KB) - not displayed