本文整理汇总了Java中com.vladsch.flexmark.util.sequence.BasedSequence.trim方法的典型用法代码示例。如果您正苦于以下问题:Java BasedSequence.trim方法的具体用法?Java BasedSequence.trim怎么用?Java BasedSequence.trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vladsch.flexmark.util.sequence.BasedSequence
的用法示例。
在下文中一共展示了BasedSequence.trim方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLineCommented
import com.vladsch.flexmark.util.sequence.BasedSequence; //导入方法依赖的package包/类
public boolean isLineCommented(final int startOfLineOffset, final int endOfLineOffset) {
Commenter commenter = getCommenterRange(startOfLineOffset, endOfLineOffset);
if (commenter != null) {
String lineCommentPrefix = commenter.getLineCommentPrefix();
String blockCommentPrefix = commenter.getCommentedBlockCommentPrefix();
if (blockCommentPrefix == null) blockCommentPrefix = commenter.getBlockCommentPrefix();
String blockCommentSuffix = commenter.getCommentedBlockCommentSuffix();
if (blockCommentSuffix == null) blockCommentSuffix = commenter.getBlockCommentSuffix();
BasedSequence chars = myChars.subSequence(startOfLineOffset, endOfLineOffset);
BasedSequence trimmed = chars.trim();
return lineCommentPrefix != null && trimmed.startsWith(lineCommentPrefix)
|| blockCommentPrefix != null && blockCommentSuffix != null && trimmed.startsWith(blockCommentPrefix) && trimmed.endsWith(blockCommentSuffix);
} else {
return false;
}
}
示例2: extractNumber
import com.vladsch.flexmark.util.sequence.BasedSequence; //导入方法依赖的package包/类
/**
* Extract a number from given sequence based on prefix/suffix, base and template
*
* @param charSequence character sequence from which to extract a number
* @param numberBase
* @return number or null if unable to extract
*/
public static long extractNumber(@NotNull CharSequence charSequence, @NotNull NumberingOptions options, int numberBase, @Nullable Ref<Integer> refMaxDigit) {
BasedSequence chars = BasedSequenceImpl.of(charSequence).trim();
if (!options.getPrefix().trim().isEmpty()) chars = chars.removePrefix(options.getPrefix().trim());
if (!options.getSuffix().trim().isEmpty()) chars = chars.removeSuffix(options.getSuffix().trim());
chars = chars.trim();
// see if we have a template and it matches somewhat
long number = 0;
boolean negative = false;
int maxDigit = refMaxDigit != null ? refMaxDigit.value : numberBase - 1;
for (int i = 0; i < chars.length(); i++) {
char c = chars.charAt(i);
if (c == '-' && i == 0) {
negative = true;
continue;
}
int digit = c >= '0' && c <= '9' ? c - '0' : c >= 'a' && c <= 'z' ? c - 'a' + 10 : c >= 'A' && c <= 'A' ? c - 'A' + 10 : -1;
if (maxDigit < digit) maxDigit = digit;
if (digit < 0 || digit >= numberBase) continue;
number *= numberBase;
number += digit;
}
if (negative) {
number = -number;
}
if (refMaxDigit != null) refMaxDigit.value = maxDigit;
return number;
}