[editor] review fixes

This commit is contained in:
Arsentiy Milchakov 2017-11-27 18:00:20 +03:00 committed by Ilya Zverev
parent 225b72e639
commit 077cafe7b1
5 changed files with 17 additions and 14 deletions

View file

@ -592,7 +592,6 @@ Java_com_mapswithme_maps_editor_Editor_nativeIsEmailValid(JNIEnv * env, jclass c
return osm::EditableMapObject::ValidateEmail(jni::ToNativeString(env, email));
}
// static bool ValidateName(string const & name)
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeIsNameValid(JNIEnv * env, jclass clazz, jstring name)
{

View file

@ -281,10 +281,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
return false;
}
if (!validateNames())
return false;
return true;
return validateNames();
}
private boolean validateNames()

View file

@ -1,5 +1,6 @@
package com.mapswithme.maps.editor;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -13,6 +14,7 @@ import com.mapswithme.maps.R;
import com.mapswithme.maps.editor.data.LocalizedName;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
public class MultilanguageAdapter extends RecyclerView.Adapter<MultilanguageAdapter.Holder>
{
@ -54,7 +56,8 @@ public class MultilanguageAdapter extends RecyclerView.Adapter<MultilanguageAdap
return mNames.size();
}
public LocalizedName getNameAtPos(int pos) { return mNames.get(pos); }
@NonNull
LocalizedName getNameAtPos(int pos) { return mNames.get(pos); }
public int getMandatoryNamesCount()
{
@ -101,7 +104,9 @@ public class MultilanguageAdapter extends RecyclerView.Adapter<MultilanguageAdap
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
UiUtils.setInputError(inputLayout, Editor.nativeIsNameValid(s.toString()) ? 0 : R.string.error_enter_correct_name);
UiUtils.setInputError(inputLayout, Editor.nativeIsNameValid(s.toString()) ?
Utils.INVALID_ID :
R.string.error_enter_correct_name);
mNames.get(getAdapterPosition()).name = s.toString();
}
});

View file

@ -7,6 +7,7 @@
#include "base/macros.hpp"
#include "base/string_utils.hpp"
#include <algorithm>
#include <codecvt>
#include <cctype>
#include <cmath>
@ -618,7 +619,7 @@ bool EditableMapObject::ValidateFlats(string const & flats)
for (auto const & rangeBorder : range)
{
if (!all_of(begin(rangeBorder), end(rangeBorder), isalnum))
if (!all_of(begin(rangeBorder), end(rangeBorder), ::isalnum))
return false;
}
}
@ -767,13 +768,13 @@ bool EditableMapObject::ValidateName(string const & name)
return true;
if (strings::IsASCIIString(name))
return regex_match(name, regex(R"(^[ A-Za-z0-9.,?!@()\-:;"'`]+$)"));
return regex_match(name, regex(R"(^[ A-Za-z0-9.,?!@$%()\-:;"'`]+$)"));
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter;
std::u32string const u32name = converter.from_bytes(name);
std::u32string const excludedSymbols = U"$%^~§><{}[]*=_#№±\n\t\r\v\f|√•π÷׶∆°";
std::u32string const excludedSymbols = U"^~§><{}[]*=_#№±\n\t\r\v\f|√•π÷׶∆°";
for (auto const ch : u32name)
{

View file

@ -190,10 +190,11 @@ UNIT_TEST(EditableMapObject_ValidateEmail)
UNIT_TEST(EditableMapObject_ValidateName)
{
vector<string> correctNames = {"abc", "абв", "ᆺᆯㅕ", "꫞ꪺꫀꪸ", "a b?c", "a!b.c", "a(b)c""a,b.c"};
vector<string> incorrectNames = {"a$bc", "a%bc", "a^bc", "a~bc", "a§bc", "a>bc", "a<bc", "a{bc",
"a[bc", "*", "a*bc", "a=bc", "a_bc", "a#bc", "a№bc", "a±bc",
"a\nbc", "a\tbc", "a\rbc", "a\vbc", "a\fbc", "a|bc", "N√",
vector<string> correctNames = {"abc", "абв", "ᆺᆯㅕ", "꫞ꪺꫀꪸ", "a b?c", "a!b.c", "a(b)c", "a,b.c",
"a$bc", "a%bc", };
vector<string> incorrectNames = {"a^bc", "a~bc", "a§bc", "a>bc", "a<bc", "a{bc", "a[bc", "*",
"a*bc", "a=bc", "a_bc", "a#bc", "a№bc", "a±bc", "a\nbc", "a\tbc",
"a\rbc", "a\vbc", "a\fbc", "a|bc", "N√",
"Hello World!\U0001F600", "Exit →", "∫0dx = C", "\U0001210A"};
for (auto const & name : correctNames)