Extras
OBCompare.h
/* Copyright 2016-2025 Jacek Piszczek/MorphOS-Team */
#import "OBObject.h"
typedef enum
{
OBLesser = -1,
OBAscending = OBLesser,
OBSame,
OBGreater,
OBDescending = OBGreater,
} OBComparisonResult;
typedef ULONG OBStringCompareOptions;
static const OBStringCompareOptions OBCaseInsensitiveCompare = (1L << 0);
static const OBStringCompareOptions OBNumericSearch = (1L << 1);
static const OBStringCompareOptions OBBackwardsSearch = (1L << 2);
OBRange.h
/* Copyright 2016-2024 Jacek Piszczek/MorphOS-Team */
#import
typedef struct _OBRange
{
ULONG location;
ULONG length;
} OBRange;
#define OBMaxRange(__xxrange__) ((__xxrange__).location + (__xxrange__).length)
static const ULONG OBNotFound = 0xFFFFFFFF;
static inline OBRange OBMakeRange(ULONG location, ULONG length) { \
OBRange range = {location, length}; \
return range; \
}
static inline BOOL OBEqualRanges(OBRange left, OBRange right) { \
return (left.location == right.location && left.length == right.length); \
}
static inline BOOL OBLocationInRange(ULONG location, OBRange range) { \
return (location >= range.location && location < OBMaxRange(range)) ? YES : NO; \
}
static inline BOOL OBEmptyRange(OBRange range) { \
return (range.location == OBNotFound); \
}
static inline OBRange OBIntersectionRange(OBRange range, OBRange otherRange) { \
ULONG min, loc, max1 = OBMaxRange(range), max2 = OBMaxRange(otherRange); \
OBRange result; \
min = (max1 < max2) ? max1 : max2; \
loc = (range.location > otherRange.location) ? range.location : otherRange.location; \
if (min < loc) \
result.location = result.length = 0; \
else { \
result.location = loc; \
result.length = min - loc; \
} \
return result; \
}
static inline OBRange OBUnionRange(OBRange range, OBRange otherRange) { \
ULONG max, loc, max1 = OBMaxRange(range), max2 = OBMaxRange(otherRange); \
OBRange result; \
max = (max1 > max2) ? max1 : max2; \
loc = (range.location < otherRange.location) ? range.location : otherRange.location; \
result.location = loc; \
result.length = max - result.location; \
return result; \
}