mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Patches submitted from May 20 to Aug 28 1997
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2406 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7b12c4af23
commit
a57d791f91
119 changed files with 16409 additions and 1698 deletions
115
Testing/nsattributedstring.m
Normal file
115
Testing/nsattributedstring.m
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
test.m
|
||||
|
||||
Test NSAttributedString and NSMutableAttributedString classes
|
||||
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
Written by: ANOQ of the sun <anoq@vip.cybercity.dk>
|
||||
Date: June 1997
|
||||
|
||||
This file is part of ...
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
If you are interested in a warranty or support for this source code,
|
||||
contact Scott Christley <scottc@net-community.com> for more information.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include "NSAttributedString.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void printAttrString(NSAttributedString *attrStr)
|
||||
{
|
||||
NSDictionary *tmpAttrDict;
|
||||
NSEnumerator *keyEnumerator;
|
||||
NSString *tmpStr;
|
||||
NSRange effectiveRange;
|
||||
unsigned int tmpLength;
|
||||
|
||||
effectiveRange = NSMakeRange(0,0);
|
||||
tmpLength = [attrStr length];
|
||||
puts("Attributed string looks like this:");
|
||||
while(NSMaxRange(effectiveRange) < tmpLength)
|
||||
{
|
||||
tmpAttrDict = [attrStr attributesAtIndex:NSMaxRange(effectiveRange)
|
||||
effectiveRange:&effectiveRange];
|
||||
printf("String: %s attributes: ",[[attrStr string] cString]);
|
||||
keyEnumerator = [tmpAttrDict keyEnumerator];
|
||||
while((tmpStr = [keyEnumerator nextObject]))
|
||||
printf("%s ",[tmpStr cString]);
|
||||
printf("location: %ld length: %ld\n",
|
||||
(long)effectiveRange.location,
|
||||
(long)effectiveRange.length);
|
||||
}
|
||||
}
|
||||
|
||||
void testAttributedString(void)
|
||||
{
|
||||
NSAttributedString *attrString;
|
||||
NSMutableAttributedString *muAttrString,*muAttrString2;
|
||||
NSMutableDictionary *attributes,*colorAttributes,*twoAttributes;
|
||||
|
||||
attributes = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
[attributes setObject:@"Helvetica 12-point"
|
||||
forKey:NSFontAttributeName];
|
||||
colorAttributes = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
[colorAttributes setObject:@"black NSColor"
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
twoAttributes = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
[twoAttributes addEntriesFromDictionary:attributes];
|
||||
[twoAttributes setObject:@"red NSColor"
|
||||
forKey:NSBackgroundColorAttributeName];
|
||||
|
||||
attrString = [[NSAttributedString alloc]
|
||||
initWithString:@"Attributed string test"
|
||||
attributes:twoAttributes];
|
||||
[attrString autorelease];
|
||||
printAttrString(attrString);
|
||||
|
||||
muAttrString = [[NSMutableAttributedString alloc]
|
||||
initWithString:@"Testing the Mutable version"
|
||||
attributes:colorAttributes];
|
||||
[muAttrString autorelease];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
[muAttrString setAttributes:attributes
|
||||
range:NSMakeRange(2,4)];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
[muAttrString setAttributes:attributes
|
||||
range:NSMakeRange(8,16)];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
[muAttrString addAttributes:colorAttributes
|
||||
range:NSMakeRange(5,12)];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
muAttrString2 = [muAttrString copy];
|
||||
printAttrString(muAttrString2);
|
||||
|
||||
[muAttrString replaceCharactersInRange:NSMakeRange(5,15)
|
||||
withAttributedString:attrString];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
[muAttrString2 replaceCharactersInRange:NSMakeRange(15,5)
|
||||
withAttributedString:attrString];
|
||||
printAttrString(muAttrString2);
|
||||
|
||||
printAttrString([muAttrString2 attributedSubstringFromRange:NSMakeRange(10,7)]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue