diff options
author | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-09 11:00:06 +0000 |
---|---|---|
committer | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-09 11:00:06 +0000 |
commit | e1cf0babff63e670e0d550b4072c22649a117fa7 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src/common/NSString+LatexConstants.m | |
parent | 49393f6f445deb37e55a81798f88242e3e99d7a0 (diff) |
Re-make trunk
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@364 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'src/common/NSString+LatexConstants.m')
-rw-r--r-- | src/common/NSString+LatexConstants.m | 204 |
1 files changed, 0 insertions, 204 deletions
diff --git a/src/common/NSString+LatexConstants.m b/src/common/NSString+LatexConstants.m deleted file mode 100644 index 1114d40..0000000 --- a/src/common/NSString+LatexConstants.m +++ /dev/null @@ -1,204 +0,0 @@ -// -// NSString+LatexConstants.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "NSString+LatexConstants.h" - -// can't use sizeof() in non-fragile ABI (eg: clang) -#define texConstantCount 62 -static NSString *texConstantNames[texConstantCount] = { - @"alpha", - @"beta", - @"gamma", - @"delta", - @"epsilon", - @"zeta", - @"eta", - @"theta", - @"iota", - @"kappa", - @"lambda", - @"mu", - @"nu", - @"xi", - @"pi", - @"rho", - @"sigma", - @"tau", - @"upsilon", - @"phi", - @"chi", - @"psi", - @"omega", - @"Gamma", - @"Delta", - @"Theta", - @"Lambda", - @"Xi", - @"Pi", - @"Sigma", - @"Upsilon", - @"Phi", - @"Psi", - @"Omega", - - @"pm", - @"to", - @"Rightarrow", - @"Leftrightarrow", - @"forall", - @"partial", - @"exists", - @"emptyset", - @"nabla", - @"in", - @"notin", - @"prod", - @"sum", - @"surd", - @"infty", - @"wedge", - @"vee", - @"cap", - @"cup", - @"int", - @"approx", - @"neq", - @"equiv", - @"leq", - @"geq", - @"subset", - @"supset", - @"cdot" -}; - -static char * texConstantCodes[texConstantCount] = { - "\u03b1","\u03b2","\u03b3","\u03b4","\u03b5","\u03b6","\u03b7", - "\u03b8","\u03b9","\u03ba","\u03bb","\u03bc","\u03bd","\u03be", - "\u03c0","\u03c1","\u03c3","\u03c4","\u03c5","\u03c6","\u03c7", - "\u03c8","\u03c9","\u0393","\u0394","\u0398","\u039b","\u039e", - "\u03a0","\u03a3","\u03a5","\u03a6","\u03a8","\u03a9", - - "\u00b1","\u2192","\u21d2","\u21d4","\u2200","\u2202","\u2203", - "\u2205","\u2207","\u2208","\u2209","\u220f","\u2211","\u221a", - "\u221e","\u2227","\u2228","\u2229","\u222a","\u222b","\u2248", - "\u2260","\u2261","\u2264","\u2265","\u2282","\u2283","\u22c5" -}; - -#define texModifierCount 10 -static NSString *texModifierNames[texModifierCount] = { - @"tiny", - @"scriptsize", - @"footnotesize", - @"small", - @"normalsize", - @"large", - @"Large", - @"LARGE", - @"huge", - @"Huge" -}; - -static NSDictionary *texConstants = nil; -static NSSet *texModifiers = nil; - -@implementation NSString(LatexConstants) - -- (NSString*)stringByExpandingLatexConstants { - - if (texConstants == nil) { - NSMutableDictionary *constants = [[NSMutableDictionary alloc] initWithCapacity:texConstantCount]; - for (int i = 0; i < texConstantCount; ++i) { - [constants setObject:[NSString stringWithUTF8String:texConstantCodes[i]] forKey:texConstantNames[i]]; - } - texConstants = constants; - } - if (texModifiers == nil) { - texModifiers = [[NSSet alloc] initWithObjects:texModifierNames count:texModifierCount]; - } - - NSMutableString *buf = [[NSMutableString alloc] initWithCapacity:[self length]]; - NSMutableString *wordBuf = [[NSMutableString alloc] initWithCapacity:10]; - - unichar c_a = [@"a" characterAtIndex:0]; - unichar c_z = [@"z" characterAtIndex:0]; - unichar c_A = [@"A" characterAtIndex:0]; - unichar c_Z = [@"Z" characterAtIndex:0]; - - int state = 0; - // a tiny little DFA to replace \\([\w*]) with unicode of $1 - unichar c; - NSString *code; - int i; - for (i = 0; i<[self length]; ++i) { - c = [self characterAtIndex:i]; - switch (state) { - case 0: - if (c=='\\') { - state = 1; - } else { - [buf appendFormat:@"%C", c]; - } - break; - case 1: - if ((c>=c_a && c<=c_z) || (c>=c_A && c<=c_Z)) { - [wordBuf appendFormat:@"%C", c]; - } else { - code = [texConstants objectForKey:wordBuf]; - if (code != nil) { - [buf appendString:code]; - } else if (![texModifiers containsObject:wordBuf]) { - [buf appendFormat:@"\\%@", wordBuf]; - } - - [wordBuf setString:@""]; - if (c=='\\') { - state = 1; - } else { - [buf appendFormat:@"%C", c]; - state = 0; - } - - } - break; - } - } - - if (state == 1) { - code = [texConstants objectForKey:wordBuf]; - if (code != nil) { - [buf appendString:code]; - } else if (![texModifiers containsObject:wordBuf]) { - [buf appendFormat:@"\\%@", wordBuf]; - } - } - - NSString *ret = [buf copy]; - [buf release]; - [wordBuf release]; - - return [ret autorelease]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 |