MCPcopy Create free account
hub / github.com/BaseXdb/basex / add

Method add

basex-core/src/main/java/org/basex/gui/text/TextEditor.java:808–877  ·  view source on GitHub ↗

Processes and adds the specified string. @param sb string to be added @param selected states if the text was selected @return returns the number spaces to move forward

(final StringBuilder sb, final boolean selected)

Source from the content-addressed store, hash-verified

806 * @return returns the number spaces to move forward
807 */
808 int add(final StringBuilder sb, final boolean selected) {
809 if(sb.isEmpty()) return 0;
810
811 int move = 0;
812 if(!selected && gui.gopts.get(GUIOptions.AUTO)) {
813 final char ch = sb.charAt(0);
814 final int next = pos + 1 < size() ? text[pos + 1] : 0;
815 final int curr = pos < size() ? text[pos] : 0;
816 final int prev = pos > 0 ? text[pos - 1] : 0;
817 final int pprv = pos > 1 ? text[pos - 2] : 0;
818 final int opening = OPENING.indexOf(ch);
819 if(opening != -1) {
820 // adds a closing to an opening bracket
821 if(CLOSING.indexOf(curr) != -1 || curr == 0 || ws(curr) || curr == '<') {
822 sb.append(CLOSING.charAt(opening));
823 move = 1;
824 }
825 } else if(CLOSING.indexOf(ch) != -1) {
826 // closing bracket: ignore if it equals next character
827 if(ch == curr) {
828 sb.setLength(0);
829 move = 1;
830 }
831 close();
832 } else if(ch == '"' || ch == '\'' || ch == '`') {
833 // quote: ignore if it equals next character
834 if(ch == curr) sb.setLength(0);
835 // add second quote
836 else if(!XMLToken.isNCChar(prev) && !XMLToken.isNCChar(curr)) sb.append(ch);
837 move = 1;
838 } else if(ch == '>') {
839 // closes an opening element
840 closeElem(sb);
841 move = 1;
842 } else if(ch == ':') {
843 // closes XQuery comments
844 if(prev == '(') {
845 sb.append(':');
846 if(curr != ')') sb.append(')');
847 move = 1;
848 }
849 } else if(ch == '~') {
850 // closes XQuery comments
851 if(prev == ':' && pprv == '(') {
852 sb.append(" ");
853 if(curr != ':') {
854 sb.append(':');
855 if(curr != ')') sb.append(')');
856 } else if(next != ')') {
857 sb.append(')');
858 }
859 move = 2;
860 }
861 } else if(ch == '-') {
862 // closes XML comments
863 if(prev == '-' && pprv == '!' && pos > 2 && text[pos - 3] == '<') {
864 sb.append(" -->");
865 move = 2;

Callers 1

enterMethod · 0.95

Calls 12

sizeMethod · 0.95
closeMethod · 0.95
isNCCharMethod · 0.95
closeElemMethod · 0.95
insertMethod · 0.95
charAtMethod · 0.80
getMethod · 0.65
appendMethod · 0.65
toStringMethod · 0.65
isEmptyMethod · 0.45
indexOfMethod · 0.45
wsMethod · 0.45

Tested by

no test coverage detected