All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polaris.builder.dbv.DbCommentSplits Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.builder.dbv;

import io.polaris.core.string.Strings;
import io.polaris.core.tuple.Tuple2;
import io.polaris.core.tuple.Tuples;

/**
 * @author Qt
 * @since 1.8,  Aug 08, 2023
 */
public class DbCommentSplits {

	/**
	 * 将表或列的注释切分为标题与备注明细两部分
	 *
	 * @param comment
	 * @return
	 */
	public static Tuple2 split(String comment) {
		String columnLabel = Strings.coalesce(comment, "");
		String columnRemark = "";
		int columnLabelSplitIdx = columnLabel.indexOf('\n');
		if (columnLabelSplitIdx <= 0) {
			columnLabelSplitIdx = columnLabel.indexOf('(');
			if (columnLabelSplitIdx <= 0) {
				columnLabelSplitIdx = columnLabel.indexOf(':');
			}
			if (columnLabelSplitIdx <= 0) {
				columnLabelSplitIdx = columnLabel.indexOf('(');
			}
			if (columnLabelSplitIdx <= 0) {
				columnLabelSplitIdx = columnLabel.indexOf(':');
			}
		}
		if (columnLabelSplitIdx > 0) {
			columnRemark = columnLabelSplitIdx < columnLabel.length() - 1 ? columnLabel.substring(columnLabelSplitIdx + 1) : "";
			columnLabel = columnLabel.substring(0, columnLabelSplitIdx);
		}
		return Tuples.of(columnLabel.trim(), columnRemark.trim());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy