]> err.no Git - sope/blob - libFoundation/Foundation/NSRange.m
fixed some NGMail framework build issue
[sope] / libFoundation / Foundation / NSRange.m
1 /* 
2    NSRange.h
3
4    Copyright (C) 1995, 1996 Ovidiu Predescu and Mircea Oancea.
5    All rights reserved.
6
7    Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
8            Mircea Oancea <mircea@jupiter.elcom.pub.ro>
9
10    This file is part of libFoundation.
11
12    Permission to use, copy, modify, and distribute this software and its
13    documentation for any purpose and without fee is hereby granted, provided
14    that the above copyright notice appear in all copies and that both that
15    copyright notice and this permission notice appear in supporting
16    documentation.
17
18    We disclaim all warranties with regard to this software, including all
19    implied warranties of merchantability and fitness, in no event shall
20    we be liable for any special, indirect or consequential damages or any
21    damages whatsoever resulting from loss of use, data or profits, whether in
22    an action of contract, negligence or other tortious action, arising out of
23    or in connection with the use or performance of this software.
24 */
25
26 #include <Foundation/common.h>
27 #include <Foundation/NSString.h>
28
29 /* Query a Range */
30 BOOL    
31 NSEqualRanges(NSRange range1, NSRange range2)
32 {
33     return ((range1.location == range2.location)
34                 && (range1.length == range2.length));
35 }
36
37 /* Compute a Range from Two Other Ranges */
38 NSRange 
39 NSUnionRange(NSRange aRange, NSRange bRange)
40 {
41     NSRange range;
42     
43     range.location = MIN(aRange.location, bRange.location);
44     range.length   = MAX(NSMaxRange(aRange), NSMaxRange(bRange)) 
45                 - range.location;
46     return range;
47 }
48
49 NSRange 
50 NSIntersectionRange (NSRange aRange, NSRange bRange)
51 {
52     NSRange range;
53     
54     if (NSMaxRange(aRange) < bRange.location
55                 || NSMaxRange(bRange) < aRange.location)
56         return NSMakeRange(0, 0);
57         
58     range.location = MAX(aRange.location, bRange.location);
59     range.length   = MIN(NSMaxRange(aRange), NSMaxRange(bRange)) 
60                 - range.location;
61     return range;
62 }
63
64 NSString*
65 NSStringFromRange(NSRange range)
66 {
67     return [NSString stringWithFormat:@"{location = %d; length = %d}",
68                 range.location, range.length];
69 }
70
71 NSRange
72 NSSRangeFromString(NSString* string)
73 {
74     return NSMakeRange(0,0);
75 }
76 /*
77   Local Variables:
78   c-basic-offset: 4
79   tab-width: 8
80   End:
81 */
82