Java文本标签处理

public void findText(List<String> textList, List<String> labelList) {
        if (null == textList || textList.size() == 0 || null == labelList || labelList.size() == 0) {
            return;
        }
        // 目标标签
        Set<String> labelSet = new HashSet<>(64);
        String targetText, labelText;
        int index, lastIndex, textLength;
        boolean legal = true;
        for (String text : textList) {
            targetText = text;
            while (StringUtils.isNoneBlank(targetText)
                    && -1 != (index = targetText.indexOf("#{"))
                    && -1 != (lastIndex = targetText.indexOf("}"))) {
                // 避免出现类似于“}}}text#{”的情况出现
                while (lastIndex < index) {
                    targetText = targetText.substring(lastIndex + 1);
                    index = targetText.indexOf("#{");
                    lastIndex = targetText.indexOf("}");
                    if (-1 == lastIndex) {
                        legal = false;
                        break;
                    }
                }
                if (!legal) {
                    break;
                }

                labelText = targetText.substring(index + 2, lastIndex);
                // 解决“#{{{{#{labelName}}”读到 {{{#{labelName 的情况
                while (-1 != (index = labelText.indexOf("#{")) && index < lastIndex) {
                    labelText = labelText.substring(index + 2);
                }
                labelSet.add(labelText.trim());

                textLength = targetText.length();
                if ((lastIndex + 1) < textLength) {
                    targetText = targetText.substring(lastIndex + 1);
                } else {
                    break;
                }
            }
        }

        // 将从文本中读到的labelSet集合中的标签,筛选出符合labelList中的目标标签
    }

 

上一篇:北京供卵机构在哪里供卵做试管选性别包成功吗?


下一篇:成都有供卵机构吗供卵做试管生孩子包成功需要多少钱?