SPB Git

Repository Public MIT

NSRange.hpp 3.1 KB 84 lines cpp

1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Foundation/NSRange.hpp4//5// Copyright 2020-2024 Apple Inc.6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11//     http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223//-------------------------------------------------------------------------------------------------------------------------------------------------------------2425#include "NSDefines.hpp"26#include "NSTypes.hpp"2728//-------------------------------------------------------------------------------------------------------------------------------------------------------------2930namespace NS31{32struct Range33{34    static Range Make(UInteger loc, UInteger len);3536    Range(UInteger loc, UInteger len);3738    bool     Equal(const Range& range) const;39    bool     LocationInRange(UInteger loc) const;40    UInteger Max() const;4142    UInteger location;43    UInteger length;44} _NS_PACKED;45}4647//-------------------------------------------------------------------------------------------------------------------------------------------------------------4849_NS_INLINE NS::Range::Range(UInteger loc, UInteger len)50    : location(loc)51    , length(len)52{53}5455//-------------------------------------------------------------------------------------------------------------------------------------------------------------5657_NS_INLINE NS::Range NS::Range::Make(UInteger loc, UInteger len)58{59    return Range(loc, len);60}6162//-------------------------------------------------------------------------------------------------------------------------------------------------------------6364_NS_INLINE bool NS::Range::Equal(const Range& range) const65{66    return (location == range.location) && (length == range.length);67}6869//-------------------------------------------------------------------------------------------------------------------------------------------------------------7071_NS_INLINE bool NS::Range::LocationInRange(UInteger loc) const72{73    return (!(loc < location)) && ((loc - location) < length);74}7576//-------------------------------------------------------------------------------------------------------------------------------------------------------------7778_NS_INLINE NS::UInteger NS::Range::Max() const79{80    return location + length;81}8283//-------------------------------------------------------------------------------------------------------------------------------------------------------------84
Files 147560ec423d00ad5f58daaf762e57546c819b00
Menu

Theme