1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2016-01-24 22:50:55 -05:00
parent 235228976e
commit 686d56fdab
77 changed files with 1543 additions and 487 deletions

View File

@@ -24,15 +24,30 @@ public class Xof_file_wkr_ {
ttl = Md5_decoder.Decode(Ttl_standardize(ttl));
return Xof_file_wkr_.Md5_fast(ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title
}
public static byte[] Ttl_standardize(byte[] ttl) {
int ttl_len = ttl.length;
for (int i = 0; i < ttl_len; i++) { // convert all spaces to _; NOTE: not same as lnki.Ttl().Page_url(), b/c Page_url does incompatible encoding
byte b = ttl[i];
if (b == Byte_ascii.Space) ttl[i] = Byte_ascii.Underline;
if (i == 0) {
if (b > 96 && b < 123) ttl[i] -= 32; // NOTE: file automatically uppercases 1st letter
public static byte[] Ttl_standardize(byte[] src) {
int len = src.length; if (len == 0) return src;
byte[] rv = null;
boolean dirty = false;
byte b = src[0];
if (b > 96 && b < 123) {
dirty = true;
rv = new byte[len];
rv[0] = (byte)(b - 32); // NOTE: [[File:]] automatically uppercases 1st letter for md5; EX:en.d:File:wikiquote-logo.png has md5 of "32" (W...) not "82" (w...); PAGE:en.d:freedom_of_speech DATE:2016-01-21
}
for (int i = 1; i < len; ++i) {
b = src[i];
if (b == Byte_ascii.Space) {
if (!dirty) {
dirty = true;
rv = new byte[len]; Bry_.Copy_by_pos(src, 0, i, rv, 0);
}
rv[i] = Byte_ascii.Underline;
}
else {
if (dirty)
rv[i] = b;
}
}
return ttl;
return dirty ? rv : src;
}
}

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import org.junit.*;
public class Xof_file_wkr__tst {
private final Xof_file_wkr___fxt fxt = new Xof_file_wkr___fxt();
@Test public void Ttl_standardize() {
fxt.Test__ttl_standardize("Abc.png" , "Abc.png"); // basic
fxt.Test__ttl_standardize("A b.png" , "A_b.png"); // spaces -> unders
fxt.Test__ttl_standardize("A b c.png" , "A_b_c.png"); // spaces -> unders; multiple
fxt.Test__ttl_standardize("abc.png" , "Abc.png"); // ucase 1st
}
}
class Xof_file_wkr___fxt {
public void Test__ttl_standardize(String src_str, String expd) {
Tfds.Eq_bry(Bry_.new_u8(expd), Xof_file_wkr_.Ttl_standardize(Bry_.new_u8(src_str)));
}
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
import org.junit.*; import gplx.xowa.files.repos.*;
public class Xof_url_bldr_tst {
private Xof_url_bldr_fxt fxt = new Xof_url_bldr_fxt();
@Before public void init() {fxt.Clear();}