SVGKSourceString.m 1013 B

123456789101112131415161718192021222324252627282930313233343536
  1. #import "SVGKSourceString.h"
  2. @implementation SVGKSourceString
  3. -(NSString *)keyForAppleDictionaries
  4. {
  5. return self.rawString;
  6. }
  7. + (SVGKSource*)sourceFromContentsOfString:(NSString*)rawString {
  8. NSInputStream* stream = [NSInputStream inputStreamWithData:[rawString dataUsingEncoding:NSUTF8StringEncoding]];
  9. //DO NOT DO THIS: let the parser do it at last possible moment (Apple has threading problems otherwise!) [stream open];
  10. SVGKSource* s = [[SVGKSourceString alloc] initWithInputSteam:stream];
  11. s.approximateLengthInBytesOr0 = [rawString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
  12. return s;
  13. }
  14. -(id)copyWithZone:(NSZone *)zone
  15. {
  16. id copy = [super copyWithZone:zone];
  17. if( copy )
  18. {
  19. /** clone bits */
  20. [copy setRawString:[self.rawString copy]];
  21. /** Finally, manually intialize the input stream, as required by super class */
  22. [copy setStream:[NSInputStream inputStreamWithData:[((SVGKSourceString*)copy).rawString dataUsingEncoding:NSUTF8StringEncoding]]];
  23. }
  24. return copy;
  25. }
  26. @end