Skip to content

Commit

Permalink
Use US locale for string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Aug 6, 2016
1 parent cd39c77 commit ffd50d1
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

public final class RedditAccountManager extends SQLiteOpenHelper {

Expand Down Expand Up @@ -98,7 +99,7 @@ public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int n

if(oldVersion == 1 && newVersion == 2) {

db.execSQL(String.format("UPDATE %s SET %2$s=TRIM(%2$s) WHERE %2$s <> TRIM(%2$s)", TABLE, FIELD_USERNAME));
db.execSQL(String.format(Locale.US, "UPDATE %s SET %2$s=TRIM(%2$s) WHERE %2$s <> TRIM(%2$s)", TABLE, FIELD_USERNAME));

} else {
throw new RuntimeException("Invalid accounts DB update: " + oldVersion + " to " + newVersion);
Expand Down Expand Up @@ -181,7 +182,7 @@ public synchronized void setDefaultAccount(final RedditAccount newDefault) {
final SQLiteDatabase db = getWritableDatabase();

db.execSQL(
String.format("UPDATE %s SET %s=(SELECT MIN(%s)-1 FROM %s) WHERE %s=?", TABLE, FIELD_PRIORITY, FIELD_PRIORITY, TABLE, FIELD_USERNAME),
String.format(Locale.US, "UPDATE %s SET %s=(SELECT MIN(%s)-1 FROM %s) WHERE %s=?", TABLE, FIELD_PRIORITY, FIELD_PRIORITY, TABLE, FIELD_USERNAME),
new String[]{newDefault.username});

reloadAccounts(db);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.quantumbadger.redreader.reddit.url.UserProfileURL;
import org.quantumbadger.redreader.views.RedditPostView;

import java.util.Locale;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -650,7 +651,8 @@ public void onUnsubscribe() {
public void onSidebar() {
final Intent intent = new Intent(this, HtmlViewActivity.class);
intent.putExtra("html", postListingFragment.getSubreddit().getSidebarHtml(PrefsUtility.isNightMode(this)));
intent.putExtra("title", String.format("%s: %s",
intent.putExtra("title", String.format(
Locale.US, "%s: %s",
getString(R.string.sidebar_activity_title),
postListingFragment.getSubreddit().url));
startActivityForResult(intent, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.quantumbadger.redreader.reddit.url.SearchPostListURL;
import org.quantumbadger.redreader.views.RedditPostView;

import java.util.Locale;
import java.util.UUID;

public class PostListingActivity extends RefreshableActivity
Expand Down Expand Up @@ -79,7 +80,7 @@ public void onCreate(final Bundle savedInstanceState) {
final RedditURLParser.RedditURL url = RedditURLParser.parseProbablePostListing(intent.getData());

if(!(url instanceof PostListingURL)) {
throw new RuntimeException(String.format("'%s' is not a post listing URL!", url.generateJsonUri()));
throw new RuntimeException(String.format(Locale.US, "'%s' is not a post listing URL!", url.generateJsonUri()));
}

controller = new PostListingController((PostListingURL)url, this);
Expand Down Expand Up @@ -292,7 +293,7 @@ public void onUnsubscribe() {
public void onSidebar() {
final Intent intent = new Intent(this, HtmlViewActivity.class);
intent.putExtra("html", fragment.getSubreddit().getSidebarHtml(PrefsUtility.isNightMode(this)));
intent.putExtra("title", String.format("%s: %s",
intent.putExtra("title", String.format(Locale.US, "%s: %s",
getString(R.string.sidebar_activity_title),
fragment.getSubreddit().url));
startActivityForResult(intent, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Locale;
import java.util.UUID;

final class CacheDbManager extends SQLiteOpenHelper {

Expand Down Expand Up @@ -97,11 +102,11 @@ synchronized LinkedList<CacheEntry> select(final URI url, final String user, fin
final String[] queryParams;

if(session == null) {
queryString = String.format("%s=%d AND %s=? AND %s=?", FIELD_STATUS, STATUS_DONE, FIELD_URL, FIELD_USER);
queryString = String.format(Locale.US, "%s=%d AND %s=? AND %s=?", FIELD_STATUS, STATUS_DONE, FIELD_URL, FIELD_USER);
queryParams = new String[] {url.toString(), user};

} else {
queryString = String.format("%s=%d AND %s=? AND %s=? AND %s=?", FIELD_STATUS, STATUS_DONE, FIELD_URL, FIELD_USER, FIELD_SESSION);
queryString = String.format(Locale.US, "%s=%d AND %s=? AND %s=? AND %s=?", FIELD_STATUS, STATUS_DONE, FIELD_URL, FIELD_USER, FIELD_SESSION);
queryParams = new String[] {url.toString(), user, session.toString()};
}

Expand Down Expand Up @@ -218,7 +223,7 @@ public synchronized ArrayList<Long> getFilesToPrune(HashSet<Long> currentFiles,

if(!entriesToDelete.isEmpty()) {

final StringBuilder query = new StringBuilder(String.format("DELETE FROM %s WHERE %s IN (", TABLE, FIELD_ID));
final StringBuilder query = new StringBuilder(String.format(Locale.US, "DELETE FROM %s WHERE %s IN (", TABLE, FIELD_ID));

query.append(entriesToDelete.remove(entriesToDelete.size() - 1));

Expand All @@ -239,6 +244,6 @@ public synchronized ArrayList<Long> getFilesToPrune(HashSet<Long> currentFiles,

public synchronized void emptyTheWholeCache() {
final SQLiteDatabase db = this.getWritableDatabase();
db.execSQL(String.format("DELETE FROM %s", TABLE));
db.execSQL(String.format(Locale.US, "DELETE FROM %s", TABLE));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;

import org.quantumbadger.redreader.account.RedditAccount;
import org.quantumbadger.redreader.activities.BugReportActivity;
import org.quantumbadger.redreader.common.General;
Expand All @@ -43,6 +42,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -264,7 +264,7 @@ public Uri getUri() throws IOException {

@Override
public String toString() {
return String.format("[ReadableCacheFile : id %d]", id);
return String.format(Locale.US, "[ReadableCacheFile : id %d]", id);
}

public long getSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -420,7 +421,7 @@ public static String sha1(final byte[] plaintext) {
digest.update(plaintext, 0, plaintext.length);
final byte[] hash = digest.digest();
final StringBuilder result = new StringBuilder(hash.length * 2);
for(byte b : hash) result.append(String.format("%02X", b));
for(byte b : hash) result.append(String.format(Locale.US, "%02X", b));
return result.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -554,23 +555,23 @@ private static String getImageUrlPatternMatch(final String url) {
if(matchQkme1.find()) {
final String imgId = matchQkme1.group(1);
if(imgId.length() > 2)
return String.format("http://i.qkme.me/%s.jpg", imgId);
return String.format(Locale.US, "http://i.qkme.me/%s.jpg", imgId);
}

final Matcher matchQkme2 = qkmePattern2.matcher(url);

if(matchQkme2.find()) {
final String imgId = matchQkme2.group(1);
if(imgId.length() > 2)
return String.format("http://i.qkme.me/%s.jpg", imgId);
return String.format(Locale.US, "http://i.qkme.me/%s.jpg", imgId);
}

final Matcher matchLvme = lvmePattern.matcher(url);

if(matchLvme.find()) {
final String imgId = matchLvme.group(1);
if(imgId.length() > 2)
return String.format("http://www.livememe.com/%s.jpg", imgId);
return String.format(Locale.US, "http://www.livememe.com/%s.jpg", imgId);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.quantumbadger.redreader.views.bezelmenu.BezelSwipeOverlay;
import org.quantumbadger.redreader.views.bezelmenu.SideToolbarOverlay;

import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

Expand Down Expand Up @@ -186,7 +187,7 @@ public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
if(goingBack && currentUrl != null && url.equals(currentUrl)) {

General.quickToast(mActivity,
String.format("Handling redirect loop (level %d)", -lastBackDepthAttempt), Toast.LENGTH_SHORT);
String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt), Toast.LENGTH_SHORT);

lastBackDepthAttempt--;

Expand Down Expand Up @@ -241,7 +242,7 @@ public void run() {
if(goingBack && url.equals(currentUrl)) {

General.quickToast(mActivity,
String.format("Handling redirect loop (level %d)", -lastBackDepthAttempt));
String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt));

lastBackDepthAttempt--;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Locale;

public class RawObjectDB<K, E extends WritableObject<K>> extends SQLiteOpenHelper {

Expand Down Expand Up @@ -168,7 +169,7 @@ public synchronized ArrayList<E> getByField(final String field, final String val

try {

final Cursor cursor = db.query(TABLE_NAME, fieldNames, String.format("%s=?", field),
final Cursor cursor = db.query(TABLE_NAME, fieldNames, String.format(Locale.US, "%s=?", field),
new String[] {value}, null, null, null);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;

public class RedditChangeDataIO {
Expand Down Expand Up @@ -82,7 +83,7 @@ public void run() {

final File dataFileTmpLocation = getDataFileWriteTmpLocation();

Log.i(TAG, String.format("Writing tmp data file at '%s'", dataFileTmpLocation.getAbsolutePath()));
Log.i(TAG, String.format(Locale.US, "Writing tmp data file at '%s'", dataFileTmpLocation.getAbsolutePath()));

final ExtendedDataOutputStream dos
= new ExtendedDataOutputStream(
Expand Down Expand Up @@ -111,7 +112,7 @@ public void run() {
final long bytes = dataFileLocation.length();
final long duration = System.currentTimeMillis() - startTime;

Log.i(TAG, String.format("%d bytes written in %d ms", bytes, duration));
Log.i(TAG, String.format(Locale.US, "%d bytes written in %d ms", bytes, duration));

} catch(final IOException e) {
Log.e(TAG, "Write failed!", e);
Expand Down Expand Up @@ -156,7 +157,7 @@ public void runInitialReadInThisThread() {
try {
final File dataFileLocation = getDataFileLocation();

Log.i(TAG, String.format("Data file at '%s'", dataFileLocation.getAbsolutePath()));
Log.i(TAG, String.format(Locale.US, "Data file at '%s'", dataFileLocation.getAbsolutePath()));

if(!dataFileLocation.exists()) {
Log.i(TAG, "Data file does not exist. Aborting read.");
Expand All @@ -174,7 +175,7 @@ public void runInitialReadInThisThread() {
final int version = dis.readInt();

if(DB_VERSION != version) {
Log.i(TAG, String.format("Wanted version %d, got %d. Aborting read.", DB_VERSION, version));
Log.i(TAG, String.format(Locale.US, "Wanted version %d, got %d. Aborting read.", DB_VERSION, version));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -99,7 +100,7 @@ public static void writeAllUsers(final ExtendedDataOutputStream dos) throws IOEx
entry.getValue().writeTo(dos);
}

Log.i(TAG, String.format("Wrote %d entries for user '%s'", entrySet.size(), username));
Log.i(TAG, String.format(Locale.US, "Wrote %d entries for user '%s'", entrySet.size(), username));
}

Log.i(TAG, "All entries written to stream.");
Expand All @@ -120,7 +121,7 @@ public static void readAllUsers(
final String username = dis.readUTF();
final int entryCount = dis.readInt();

Log.i(TAG, String.format("Reading %d entries for user '%s'", entryCount, username));
Log.i(TAG, String.format(Locale.US, "Reading %d entries for user '%s'", entryCount, username));

final HashMap<String, Entry> entries = new HashMap<>(entryCount);

Expand All @@ -135,11 +136,11 @@ public static void readAllUsers(
final RedditAccount account = RedditAccountManager.getInstance(context).getAccount(username);

if(account == null) {
Log.i(TAG, String.format("Skipping user '%s' as the account no longer exists", username));
Log.i(TAG, String.format(Locale.US, "Skipping user '%s' as the account no longer exists", username));

} else {
getInstance(account).insertAll(entries);
Log.i(TAG, String.format("Finished inserting entries for user '%s'", username));
Log.i(TAG, String.format(Locale.US, "Finished inserting entries for user '%s'", username));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.quantumbadger.redreader.common.UnexpectedInternalStateException;
import org.quantumbadger.redreader.io.WritableObject;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -33,7 +34,7 @@ public String getKey() {
try {
return getCanonicalName();
} catch(InvalidSubredditNameException e) {
throw new UnexpectedInternalStateException(String.format("Cannot save subreddit '%s'", url));
throw new UnexpectedInternalStateException(String.format(Locale.US, "Cannot save subreddit '%s'", url));
}
}

Expand All @@ -45,7 +46,7 @@ public long getTimestamp() {

public static final class InvalidSubredditNameException extends Exception {
public InvalidSubredditNameException(String subredditName) {
super(String.format("Invalid subreddit name '%s'.", subredditName == null ? "NULL" : subredditName));
super(String.format(Locale.US, "Invalid subreddit name '%s'.", subredditName == null ? "NULL" : subredditName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import android.opengl.GLES20;

import java.util.Locale;

public abstract class RRGLProgram {

private final int mHandle;
Expand Down Expand Up @@ -62,7 +64,7 @@ private void compileAndAttachShader(final int type, final String source) {
if(compileStatus[0] == 0) {
final String log = GLES20.glGetShaderInfoLog(mHandle);
GLES20.glDeleteShader(shaderHandle);
throw new RuntimeException(String.format("Shader compile error: \"%s\".", log));
throw new RuntimeException(String.format(Locale.US, "Shader compile error: \"%s\".", log));
}

GLES20.glAttachShader(mHandle, shaderHandle);
Expand All @@ -86,7 +88,7 @@ private void link() {
if(linkStatus[0] == 0) {
final String log = GLES20.glGetProgramInfoLog(mHandle);
GLES20.glDeleteProgram(mHandle);
throw new RuntimeException(String.format("Linker error: \"%s\".", log));
throw new RuntimeException(String.format(Locale.US, "Linker error: \"%s\".", log));
}

GLES20.glDetachShader(mHandle, mFragmentShaderHandle);
Expand Down

0 comments on commit ffd50d1

Please sign in to comment.