Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/URL-parser/Java/url-parser-1.java
Normal file
6
Task/URL-parser/Java/url-parser-1.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
URI uri;
|
||||
try {
|
||||
uri = new URI("foo://example.com:8042/over/there?name=ferret#nose");
|
||||
} catch (URISyntaxException exception) {
|
||||
/* invalid URI */
|
||||
}
|
||||
1
Task/URL-parser/Java/url-parser-2.java
Normal file
1
Task/URL-parser/Java/url-parser-2.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
uri.getScheme()
|
||||
40
Task/URL-parser/Java/url-parser-3.java
Normal file
40
Task/URL-parser/Java/url-parser-3.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MailTo {
|
||||
private final To to;
|
||||
private List<Field> fields;
|
||||
|
||||
public MailTo(String string) {
|
||||
if (string == null)
|
||||
throw new NullPointerException();
|
||||
if (string.isBlank() || !string.toLowerCase().startsWith("mailto:"))
|
||||
throw new IllegalArgumentException("Requires 'mailto' scheme");
|
||||
string = string.substring(string.indexOf(':') + 1);
|
||||
/* we can use the 'URLDecoder' class to decode any entities */
|
||||
string = URLDecoder.decode(string, StandardCharsets.UTF_8);
|
||||
/* the address and fields are separated by a '?' */
|
||||
int indexOf = string.indexOf('?');
|
||||
String[] address;
|
||||
if (indexOf == -1)
|
||||
address = string.split("@");
|
||||
else {
|
||||
address = string.substring(0, indexOf).split("@");
|
||||
string = string.substring(indexOf + 1);
|
||||
/* each field is separated by a '&' */
|
||||
String[] fields = string.split("&");
|
||||
String[] field;
|
||||
this.fields = new ArrayList<>(fields.length);
|
||||
for (String value : fields) {
|
||||
field = value.split("=");
|
||||
this.fields.add(new Field(field[0], field[1]));
|
||||
}
|
||||
}
|
||||
to = new To(address[0], address[1]);
|
||||
}
|
||||
|
||||
record To(String user, String host) { }
|
||||
record Field(String name, String value) { }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue