/** VOGen.bsh - a BeanShell macro for the jEdit text editor that merg lines of String or int values into one quoted line suitable for use in a SQL query, like "in ('a','b','c')". Copyright (C) 2004 Jia Zhiming jiazhimi@yahoo.com.cn This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ void merg() { int lineCnt = textArea.getLineCount(); StringBuffer sb = new StringBuffer(); String toWrite = null; String inLine = null; boolean numValue = false; /** * Scan to find the format of the file content (int/text) */ for (int i = 0; i < lineCnt; i++) { inLine = textArea.getLineText(i).trim(); if (inLine.equals("")) continue; try { Integer.parseInt(inLine); } catch (NumberFormatException ie) { try { Long.parseLong(inLine); } catch (NumberFormatException le) { try { Float.parseFloat(inLine); } catch (NumberFormatException fe) { try { Double.parseDouble(inLine); } catch (NumberFormatException de) { numValue = false; break; } } } } numValue = true; } for (int i = 0; i < lineCnt; i++) { inLine = textArea.getLineText(i).trim(); if (inLine.equals("")) continue; if (numValue) toWrite = inLine; else toWrite = "\'" + inLine + "\'"; if (i == 0) sb.append(" in (" + toWrite); else if (i == (lineCnt - 1)) sb.append("," + toWrite + ")"); else sb.append("," + toWrite); } textArea.setText(sb.toString()); textArea.selectAll(); Registers.copy(textArea,'$'); } if( buffer.isReadOnly() ) Macros.error( view, "Buffer is read-only." ); else merg();