You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
8.3 KiB

/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2020 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// NSString+QMUI.h
// qmui
//
// Created by QMUI Team on 15/7/20.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CGBase.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSString (QMUI)
/// 将字符串按一个一个字符拆成数组,类似 JavaScript 里的 split(""),如果多个空格,则每个空格也会当成一个 item
@property(nullable, readonly, copy) NSArray<NSString *> *qmui_toArray;
/// 将字符串按一个一个字符拆成数组,类似 JavaScript 里的 split(""),但会自动过滤掉空白字符
@property(nullable, readonly, copy) NSArray<NSString *> *qmui_toTrimmedArray;
/// 去掉头尾的空白字符
@property(readonly, copy) NSString *qmui_trim;
/// 去掉整段文字内的所有空白字符(包括换行符)
@property(readonly, copy) NSString *qmui_trimAllWhiteSpace;
/// 将文字中的换行符替换为空格
@property(readonly, copy) NSString *qmui_trimLineBreakCharacter;
/// 把该字符串转换为对应的 md5
@property(readonly, copy) NSString *qmui_md5;
/// 返回一个符合 query value 要求的编码后的字符串,例如&、#、=等字符均会被变为 %xxx 的编码
/// @see `NSCharacterSet (QMUI) qmui_URLUserInputQueryAllowedCharacterSet`
@property(nullable, readonly, copy) NSString *qmui_stringByEncodingUserInputQuery;
/// 把当前文本的第一个字符改为大写,其他的字符保持不变,例如 backgroundView.qmui_capitalizedString -> BackgroundView(系统的 capitalizedString 会变成 Backgroundview)
@property(nullable, readonly, copy) NSString *qmui_capitalizedString;
/**
* UI上的展示问题
* @link http://www.croton.su/en/uniblock/Diacriticals.html @/link
*/
@property(nullable, readonly, copy) NSString *qmui_removeMagicalChar;
/**
* 2 1
*/
@property(readonly) NSUInteger qmui_lengthWhenCountingNonASCIICharacterAsTwo;
/**
* index emoji "character sequences" emoji 1-4
*
* 😊😞4 [string qmui_substringAvoidBreakingUpCharacterSequencesFromIndex:1]😊😞
* [string substringFromIndex:1]?😞? emoji
*
* @param index index
* @param lessValue
* @param countingNonASCIICharacterAsTwo 1 2
* @return
*/
- (NSString *)qmui_substringAvoidBreakingUpCharacterSequencesFromIndex:(NSUInteger)index lessValue:(BOOL)lessValue countingNonASCIICharacterAsTwo:(BOOL)countingNonASCIICharacterAsTwo;
/**
* `qmui_substringAvoidBreakingUpCharacterSequencesFromIndex: lessValue:YES` countingNonASCIICharacterAsTwo:NO
* @see qmui_substringAvoidBreakingUpCharacterSequencesFromIndex:lessValue:countingNonASCIICharacterAsTwo:
*/
- (NSString *)qmui_substringAvoidBreakingUpCharacterSequencesFromIndex:(NSUInteger)index;
/**
* index emoji "character sequences" emoji 1-4
*
* 😊😞4 [string qmui_substringAvoidBreakingUpCharacterSequencesToIndex:1 lessValue:NO countingNonASCIICharacterAsTwo:NO]😊
* [string substringToIndex:1]?? emoji
*
* @param index index
* @param lessValue character sequences
* @param countingNonASCIICharacterAsTwo 1 2
* @return
*/
- (NSString *)qmui_substringAvoidBreakingUpCharacterSequencesToIndex:(NSUInteger)index lessValue:(BOOL)lessValue countingNonASCIICharacterAsTwo:(BOOL)countingNonASCIICharacterAsTwo;
/**
* `qmui_substringAvoidBreakingUpCharacterSequencesToIndex:lessValue:YES` countingNonASCIICharacterAsTwo:NO
* @see qmui_substringAvoidBreakingUpCharacterSequencesToIndex:lessValue:countingNonASCIICharacterAsTwo:
*/
- (NSString *)qmui_substringAvoidBreakingUpCharacterSequencesToIndex:(NSUInteger)index;
/**
* range emoji "character sequences" emoji 1-4
*
* 😊😞4 lessValue (0, 1) (0, 2) 😊
* lessValue (0, 1) (0, 2)😊
*
* @param range
* @param lessValue character sequences
* @param countingNonASCIICharacterAsTwo 1 2
* @return
*/
- (NSString *)qmui_substringAvoidBreakingUpCharacterSequencesWithRange:(NSRange)range lessValue:(BOOL)lessValue countingNonASCIICharacterAsTwo:(BOOL)countingNonASCIICharacterAsTwo;
/**
* `qmui_substringAvoidBreakingUpCharacterSequencesWithRange:lessValue:YES` countingNonASCIICharacterAsTwo:NO
* @see qmui_substringAvoidBreakingUpCharacterSequencesWithRange:lessValue:countingNonASCIICharacterAsTwo:
*/
- (NSString *)qmui_substringAvoidBreakingUpCharacterSequencesWithRange:(NSRange)range;
/**
* emoji表情的情况emoji表情占1-4length
* @param index
*/
- (NSString *)qmui_stringByRemoveCharacterAtIndex:(NSUInteger)index;
/**
* emoji表情的情况emoji表情占1-4length
* @see `qmui_stringByRemoveCharacterAtIndex:`
*/
- (NSString *)qmui_stringByRemoveLastCharacter;
/**
@param pattern
@return nil
*/
- (NSString *)qmui_stringMatchedByPattern:(NSString *)pattern;
/**
*
* @param pattern
* @param replacement
* @return
*/
- (NSString *)qmui_stringByReplacingPattern:(NSString *)pattern withString:(NSString *)replacement;
/// 把某个十进制数字转换成十六进制的数字的字符串,例如“10”->“A”
+ (NSString *)qmui_hexStringWithInteger:(NSInteger)integer;
/// 把参数列表拼接成一个字符串并返回,相当于用另一种语法来代替 [NSString stringWithFormat:]
+ (NSString *)qmui_stringByConcat:(id)firstArgv, ...;
/**
* 100->"01:40"
*/
+ (NSString *)qmui_timeStringWithMinsAndSecsFromSecs:(double)seconds;
@end
@interface NSString (QMUI_StringFormat)
+ (instancetype)qmui_stringWithNSInteger:(NSInteger)integerValue;
+ (instancetype)qmui_stringWithCGFloat:(CGFloat)floatValue;
+ (instancetype)qmui_stringWithCGFloat:(CGFloat)floatValue decimal:(NSUInteger)decimal;
@end
NS_ASSUME_NONNULL_END