[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-09-01 Thread bdk
Ok, so here's the code I'm using ATM:

8 - - - - - - - - -
// InputFilter for file names
// use like this:
//
//   edittext.setFilters(new InputFilter[]{cFilenameInputFilter});

static final InputFilter cFilenameInputFilter = new InputFilter()
{
  public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend)
  {
for (int i = start; i  end; i++)
{
  int ch = source.charAt(i);
  boolean is_unicode_punctuation = false;

  switch (Character.getType(ch)) {
case Character.CURRENCY_SYMBOL:
case Character.CONNECTOR_PUNCTUATION:
case Character.FINAL_QUOTE_PUNCTUATION:
case Character.INITIAL_QUOTE_PUNCTUATION:
case Character.DASH_PUNCTUATION:
case Character.START_PUNCTUATION:
case Character.END_PUNCTUATION:
case Character.OTHER_PUNCTUATION:
  is_unicode_punctuation = true;
break;
  }

// check against Forbidden chars:
// 'reverse solidus': 
http://blogs.msdn.com/b/michkap/archive/2005/10/12/479561.
final char reverse_solidus = 0x005c;
final String forbidden_chars = |?*:\+[]/\\ + reverse_solidus;
boolean is_allowed = (forbidden_chars.indexOf(ch) == -1);

boolean is_valid_char = is_allowed 
(Character.isLetterOrDigit(ch) || is_unicode_punctuation);

if(is_valid_char == false)
{
  return ; // ops
}
  }

 return null; // go on, char should be fine
}
};

8 - - - - - - - - -

best

--
Mathieu

On Aug 30, 1:22 pm, Daniel Drozdzewski daniel.drozdzew...@gmail.com
wrote:
 On 30 August 2011 12:17,bdkmathieu.b...@gmail.com wrote:

  A possibly catch-all solution:

   http://download.oracle.com/javase/tutorial/i18n/text/charintro.html

  :)

 Indeed!
 That should work just fine and avoids use of RegEx.

 Thanks!

 --
 Daniel

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-09-01 Thread Chris
Nice, tidy.  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-30 Thread bdk
Thanks Chris, that's for sure useful :)

--
Mathieu

On Aug 25, 5:00 pm, Chris crehb...@gmail.com wrote:
 On Thursday, August 25, 2011 4:35:33 AM UTC-4, bdk wrote:

  I'll go hunting for an 'official' list of locale-specific path
  separators...

 There's a constant in java.io.File named 'separator' which gives you the
 localized, system-specific file separator string.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-30 Thread Daniel Drozdzewski
On 30 August 2011 10:57, bdk mathieu.b...@gmail.com wrote:
 Thanks Chris, that's for sure useful :)

Mathieu,

Instead of doing cat and mouse chase of all possible path separators,
just define, what characters you allow in a reg-ex. This will be much
easier, as the file names have quite limited number of allowed chars.

It is true that System.getProperty(path.separator) or
File.pathSeparator will store the path separator for current locale.
But as you see, it will return only the separator for the current
locale, while you need to filter them all (I think).

In other words me defining the file path with Japanese Yen or Korean
Won while in en locale and then quitting your app, changing locale
to jp or kr and restarting your app could avoid your checks.


-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-30 Thread bdk
Hmm... Daniel, that's for sure the best approach!

This one looks like nice option (using InputFilter):

 
http://stackoverflow.com/questions/5500060/android-input-type-for-only-non-numeric-chars

--
Mathieu



On Aug 30, 12:07 pm, Daniel Drozdzewski daniel.drozdzew...@gmail.com
wrote:
 On 30 August 2011 10:57, bdk mathieu.b...@gmail.com wrote:

  Thanks Chris, that's for sure useful :)

 Mathieu,

 Instead of doing cat and mouse chase of all possible path separators,
 just define, what characters you allow in a reg-ex. This will be much
 easier, as the file names have quite limited number of allowed chars.

 It is true that System.getProperty(path.separator) or
 File.pathSeparator will store the path separator for current locale.
 But as you see, it will return only the separator for the current
 locale, while you need to filter them all (I think).

 In other words me defining the file path with Japanese Yen or Korean
 Won while in en locale and then quitting your app, changing locale
 to jp or kr and restarting your app could avoid your checks.

 --
 Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-30 Thread bdk
Ok, here some more resources:

RegExp example:
 
http://www.devdaily.com/blog/post/java/remove-non-alphanumeric-characters-java-string

Windows filenames  paths:
 http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx

 - - -

On the other hand: how to deal with non-latin alphabets?
(that is, allowing Unicode file names? e.g. Japanese, Korean,
Cirillic, Greek, ... filenames?)

See for instance this: http://kourge.net/projects/regexp-unicode-block

Maybe in this case it would still be easier to go for the mouse-cat
solution which apparently is a bit less daunting...

... well, for now I'll stick with alphanumeric RegExp:
- good side: such files would be easier to index if made public
- downside: not everyone in the world knows a latin-alphabet based
language...?

--
Mathieu

On Aug 30, 12:37 pm, bdk mathieu.b...@gmail.com wrote:
 Hmm... Daniel, that's for sure the best approach!

 This one looks like nice option (using InputFilter):

  http://stackoverflow.com/questions/5500060/android-input-type-for-onl...

 --
 Mathieu

 On Aug 30, 12:07 pm, Daniel Drozdzewski daniel.drozdzew...@gmail.com
 wrote:

  On 30 August 2011 10:57, bdk mathieu.b...@gmail.com wrote:

   Thanks Chris, that's for sure useful :)

  Mathieu,

  Instead of doing cat and mouse chase of all possible path separators,
  just define, what characters you allow in a reg-ex. This will be much
  easier, as the file names have quite limited number of allowed chars.

  It is true that System.getProperty(path.separator) or
  File.pathSeparator will store the path separator for current locale.
  But as you see, it will return only the separator for the current
  locale, while you need to filter them all (I think).

  In other words me defining the file path with Japanese Yen or Korean
  Won while in en locale and then quitting your app, changing locale
  to jp or kr and restarting your app could avoid your checks.

  --
  Daniel Drozdzewski



-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-30 Thread Daniel Drozdzewski
On 30 August 2011 11:57, bdk mathieu.b...@gmail.com wrote:
 Ok, here some more resources:

 RegExp example:
  http://www.devdaily.com/blog/post/java/remove-non-alphanumeric-characters-java-string

 Windows filenames  paths:
  http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx


Good spot Mathieu about Unicode characters!

You have to build your reg-ex using character classes designed to deal
with this.

go to:

http://download.oracle.com/javase/1,5.0/docs/api/java/util/regex/Pattern.html#sum

...and have a look at 'Classes for Unicode blocks and categories' section.

\p{L}

as a reg-ex marks letters regardless of the alphabet/script used.


-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-30 Thread bdk
A possibly catch-all solution:

  http://download.oracle.com/javase/tutorial/i18n/text/charintro.html

:)

--
Mathieu

On Aug 30, 1:11 pm, Daniel Drozdzewski daniel.drozdzew...@gmail.com
wrote:
 On 30 August 2011 11:57, bdk mathieu.b...@gmail.com wrote:

  Ok, here some more resources:

  RegExp example:
   http://www.devdaily.com/blog/post/java/remove-non-alphanumeric-charac...

  Windows filenames  paths:
   http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx

 Good spot Mathieu about Unicode characters!

 You have to build your reg-ex using character classes designed to deal
 with this.

 go to:

 http://download.oracle.com/javase/1,5.0/docs/api/java/util/regex/Patt...

 ...and have a look at 'Classes for Unicode blocks and categories' section.

 \p{L}

 as a reg-ex marks letters regardless of the alphabet/script used.

 --
 Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-30 Thread Daniel Drozdzewski
On 30 August 2011 12:17, bdk mathieu.b...@gmail.com wrote:
 A possibly catch-all solution:

  http://download.oracle.com/javase/tutorial/i18n/text/charintro.html

 :)


Indeed!
That should work just fine and avoids use of RegEx.

Thanks!

--
Daniel

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-25 Thread bdk
Thanks for your suggestion, Daniel.

Actually it appears to me like a new input method would need to be
implemented (by Google...? :) at least for soft-keyboard, so the user
just sees the allowed keys (just the forbidden ones are not shown).
And, with a flag to enable or disable the path-separator char (fun
read: http://blogs.msdn.com/b/oldnewthing/archive/2005/10/14/481044.aspx
)
On the other hand your suggestion seems like a good (the only?) option
for an hardware keyboard.

I'll go hunting for an 'official' list of locale-specific path
separators...
Maybe it's just Yen, Won and slashes-backslashes...

best

--
Mathieu

On Aug 24, 6:39 pm, Daniel Drozdzewski daniel.drozdzew...@gmail.com
wrote:
 On 24 August 2011 17:05, bdk mathieu.b...@gmail.com wrote:



  Hi

  I'm showing the user a Save as... dialog to save files, and I'd like
  to disable a set of 'reserved characters' into a related EditText
  field.

  Let's say, something like:

   private static final String ReservedChars = |\\?*\:+/'¥;

   (useful read:http://en.wikipedia.org/wiki/Filename)

  I have to be careful not to use chars not compatible with other
  filesystems like Windows (for instance: ? or   would make the file
  unusable in a Win* filesystem)

  Moreover, I don't want the user to be able to put sequences like ../
  or /foo/bar/filename.xxx to access other paths.

  This also brings up another point: _all_ possible filepath separators
  should be forbidden (for instance, ¥ is the filepath separator on
  Japanese locale computers).

  So, what would be the most elegant solution to filter out these
  characters from user input?
  I'm also thinking about automatically replacing the forbidden chars
  with underscores, but it's not really user-friendly.

  I looked 
  intohttp://developer.android.com/reference/android/text/InputType.html
  but something like InputType.TYPE_CLASS_FILE_NAME is missing...

  TYPE_TEXT_VARIATION_URI does not seem an option since apparently the
  soft keyboard ends up containing chars like: / *  ? ¥ and... smileys?

  For now I've tried with:

                 EditText myEditText = new EditText(activity);
                 myEditText.setSingleLine();
                 myEditText.setInputType(InputType.TYPE_CLASS_TEXT |
  InputType.TYPE_TEXT_VARIATION_URI);

  to no luck.

  Now I'm reading 
  across:http://stackoverflow.com/questions/6626283/how-to-use-inputconnection...
  ...

  best

 Just add a listener to EditText.

 In the listener you capture the text change event and filter through
 only allowed characters.
 --
 Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-25 Thread bdk
This one looks like a good read on the file-path separators question:

  http://blogs.msdn.com/b/michkap/archive/2005/09/17/469941.aspx

--
Mathieu

On Aug 25, 10:35 am, bdk mathieu.b...@gmail.com wrote:
 Thanks for your suggestion, Daniel.

 Actually it appears to me like a new input method would need to be
 implemented (by Google...? :) at least for soft-keyboard, so the user
 just sees the allowed keys (just the forbidden ones are not shown).
 And, with a flag to enable or disable the path-separator char (fun
 read:http://blogs.msdn.com/b/oldnewthing/archive/2005/10/14/481044.aspx
 )
 On the other hand your suggestion seems like a good (the only?) option
 for an hardware keyboard.

 I'll go hunting for an 'official' list of locale-specific path
 separators...
 Maybe it's just Yen, Won and slashes-backslashes...

 best

 --
 Mathieu

 On Aug 24, 6:39 pm, Daniel Drozdzewski daniel.drozdzew...@gmail.com
 wrote:

  On 24 August 2011 17:05,bdkmathieu.b...@gmail.com wrote:

   Hi

   I'm showing the user a Save as... dialog to save files, and I'd like
   to disable a set of 'reserved characters' into a related EditText
   field.

   Let's say, something like:

    private static final String ReservedChars = |\\?*\:+/'¥;

    (useful read:http://en.wikipedia.org/wiki/Filename)

   I have to be careful not to use chars not compatible with other
   filesystems like Windows (for instance: ? or   would make the file
   unusable in a Win* filesystem)

   Moreover, I don't want the user to be able to put sequences like ../
   or /foo/bar/filename.xxx to access other paths.

   This also brings up another point: _all_ possible filepath separators
   should be forbidden (for instance, ¥ is the filepath separator on
   Japanese locale computers).

   So, what would be the most elegant solution to filter out these
   characters from user input?
   I'm also thinking about automatically replacing the forbidden chars
   with underscores, but it's not really user-friendly.

   I looked 
   intohttp://developer.android.com/reference/android/text/InputType.html
   but something like InputType.TYPE_CLASS_FILE_NAME is missing...

   TYPE_TEXT_VARIATION_URI does not seem an option since apparently the
   soft keyboard ends up containing chars like: / *  ? ¥ and... smileys?

   For now I've tried with:

                  EditText myEditText = new EditText(activity);
                  myEditText.setSingleLine();
                  myEditText.setInputType(InputType.TYPE_CLASS_TEXT |
   InputType.TYPE_TEXT_VARIATION_URI);

   to no luck.

   Now I'm reading 
   across:http://stackoverflow.com/questions/6626283/how-to-use-inputconnection...
   ...

   best

  Just add a listener to EditText.

  In the listener you capture the text change event and filter through
  only allowed characters.
  --
  Daniel Drozdzewski



-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Disabling a set of 'reserved characters' from user Input?

2011-08-25 Thread Chris


On Thursday, August 25, 2011 4:35:33 AM UTC-4, bdk wrote:


 I'll go hunting for an 'official' list of locale-specific path 
 separators... 


There's a constant in java.io.File named 'separator' which gives you the 
localized, system-specific file separator string.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en