1
0
mirror of https://github.com/quinton-ashley/java2js synced 2024-12-29 10:11:54 +01:00
java2js/jdk/java/lang/String.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-11-15 20:02:30 -05:00
jdk.imports['java.lang.String'].load = async () => {
const Formatter = await jdk.import('java.util.Formatter');
// String is special, I just extended js String prototype
String.prototype.hashCode = function () {
2022-01-14 12:41:43 -05:00
var hash = 0,
i,
chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
2021-09-23 01:41:44 -05:00
}
2022-01-14 12:41:43 -05:00
return hash;
2021-11-15 20:02:30 -05:00
};
String.prototype.isEmpty = function () {
return this.length == 0;
};
String.prototype.contains = function (substr) {
return this.includes(substr);
};
2021-11-18 15:01:15 -05:00
String.prototype.equals = function (o) {
return this == o;
};
2021-11-19 09:56:21 -05:00
String.prototype.toCharArray = function (o) {
return this.split('');
};
2021-11-15 20:02:30 -05:00
// static methods
String.valueOf = (c) => {
return c.toString();
};
String.format = (format, ...args) => {
return new Formatter().format(format, ...args);
};
jdk.java.lang.String = String;
2022-06-27 19:09:22 -05:00
Number.prototype.toUpperCase = function () {
return this + '';
};
Number.prototype.toLowerCase = function () {
return this + '';
};
2021-09-23 23:26:42 -05:00
};