Skip to content
Snippets Groups Projects
Commit f510d645 authored by tjc's avatar tjc
Browse files

decode and encode changed to use array

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@2795 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 9b2de5a9
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFStreamFeature.java,v 1.15 2005-06-08 11:01:25 tjc Exp $ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFStreamFeature.java,v 1.16 2005-06-08 15:19:38 tjc Exp $
*/ */
package uk.ac.sanger.artemis.io; package uk.ac.sanger.artemis.io;
...@@ -35,7 +35,7 @@ import java.util.StringTokenizer; ...@@ -35,7 +35,7 @@ import java.util.StringTokenizer;
* A StreamFeature that thinks it is a GFF feature. * A StreamFeature that thinks it is a GFF feature.
* *
* @author Kim Rutherford * @author Kim Rutherford
* @version $Id: GFFStreamFeature.java,v 1.15 2005-06-08 11:01:25 tjc Exp $ * @version $Id: GFFStreamFeature.java,v 1.16 2005-06-08 15:19:38 tjc Exp $
**/ **/
public class GFFStreamFeature extends SimpleDocumentFeature public class GFFStreamFeature extends SimpleDocumentFeature
...@@ -261,82 +261,64 @@ public class GFFStreamFeature extends SimpleDocumentFeature ...@@ -261,82 +261,64 @@ public class GFFStreamFeature extends SimpleDocumentFeature
*/ */
private String decode(String s) private String decode(String s)
{ {
int ind; final String map[][] = {
{ " ", "%20" }, // white space
// white space { ",", "%2C" }, // comma
while( (ind = s.indexOf("%20")) > -1) { ";", "%3B" }, // semi-colon
s = s.substring(0,ind) + " " + s.substring(ind+3); { "=", "%3D" }, // equals
{ "\t", "%09" }, // tab
// comma { " ", "+" }, // white space
while( (ind = s.indexOf("%2C")) > -1) { "(", "%28" }, // left bracket
s = s.substring(0,ind) + "," + s.substring(ind+3); { ")", "%29" } // right bracket )
};
// white space
while( (ind = s.indexOf("+")) > -1)
s = s.substring(0,ind) + " " + s.substring(ind+1);
// semi-colon
while( (ind = s.indexOf("%3B")) > -1)
s = s.substring(0,ind) + ";" + s.substring(ind+3);
// equals
while( (ind = s.indexOf("%3D")) > -1)
s = s.substring(0,ind) + "=" + s.substring(ind+3);
//tabs
while( (ind = s.indexOf("%09")) > -1)
s = s.substring(0,ind) + "=" + s.substring(ind+3);
// left bracket ( int ind;
while( (ind = s.indexOf("%28")) > -1) String enc;
s = s.substring(0,ind) + "=" + s.substring(ind+3); String dec;
// right bracket )
while( (ind = s.indexOf("%29")) > -1)
s = s.substring(0,ind) + "=" + s.substring(ind+3);
// ind = -1;
// while( (ind = s.indexOf("=",ind+2)) > -1)
// s = s.substring(0,ind+1) + "\"" + s.substring(ind+1);
// ind = -1; for(int i=0; i<map.length; i++)
// while( (ind = s.indexOf(";",ind+2)) > -1) {
// s = s.substring(0,ind+1) + "\"" + s.substring(ind+1); enc = map[i][1];
dec = map[i][0];
while( (ind = s.indexOf(enc)) > -1)
s = s.substring(0,ind) + dec + s.substring(ind+enc.length());
}
return s; return s;
} }
/**
*
* For gff-version 3:
* http://song.sourceforge.net/gff3-jan04.shtml
*
* Add URL escaping rule (e.g. space="%20" or "+")
*
*/
private String encode(String s) private String encode(String s)
{ {
int ind; final String map[][] = {
// { " ", "%20" }, // white space
// white space { ",", "%2C" }, // comma
//while( (ind = s.indexOf(" ")) > -1) { ";", "%3B" }, // semi-colon
// s = s.substring(0,ind) + "%20" + s.substring(ind+1); { "=", "%3D" }, // equals
{ "\t", "%09" }, // tab
{ " ", "+" }, // white space
{ "(", "%28" }, // left bracket
{ ")", "%29" } // right bracket )
};
// comma int ind;
while( (ind = s.indexOf(",")) > -1) String enc;
s = s.substring(0,ind) + "%2C" + s.substring(ind+1); String dec;
// semi-colon
while( (ind = s.indexOf(";")) > -1)
s = s.substring(0,ind) + "%3B" + s.substring(ind+1);
// equals
while( (ind = s.indexOf("=")) > -1)
s = s.substring(0,ind) + "%3D" + s.substring(ind+1);
//tabs
while( (ind = s.indexOf("\t")) > -1)
s = s.substring(0,ind) + "%09" + s.substring(ind+1);
// left bracket (
while( (ind = s.indexOf(")")) > -1)
s = s.substring(0,ind) + "%28" + s.substring(ind+1);
// right bracket ) for(int i=0; i<map.length; i++)
while( (ind = s.indexOf(")")) > -1) {
s = s.substring(0,ind) + "%29" + s.substring(ind+1); enc = map[i][1];
dec = map[i][0];
while( (ind = s.indexOf(dec)) > -1 )
s = s.substring(0,ind) + enc + s.substring(ind+1);
}
return s; return s;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment