[iOS] Improve flag handling from iOS settings

There are two areas to improve our flag handling. First, the default iOS
keyboard replaces two dashes with an em dash, so typing that in as a
flag is difficult. Second, all flags start with dashes, so the code
can fallback to add them if they don't exist.

Bug: 964930
Change-Id: Ifeee11343381b7a8587499512fab1c3f78ba7548
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617839
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661341}
diff --git a/ios/chrome/browser/about_flags.mm b/ios/chrome/browser/about_flags.mm
index b98bb09..54014c8 100644
--- a/ios/chrome/browser/about_flags.mm
+++ b/ios/chrome/browser/about_flags.mm
@@ -622,6 +622,17 @@
           [NSString stringWithFormat:@"FreeformCommandLineFlag%d", i];
       NSString* flag = [defaults stringForKey:key];
       if ([flag length]) {
+        // iOS keyboard replaces -- with —, so undo that.
+        flag = [flag stringByReplacingOccurrencesOfString:@"—"
+                                               withString:@"--"
+                                                  options:0
+                                                    range:NSMakeRange(0, 1)];
+        // To make things easier, allow flags with no dashes by prepending them
+        // here. This also allows for flags that just have one dash if they
+        // exist.
+        if (![flag hasPrefix:@"-"]) {
+          flag = [@"--" stringByAppendingString:flag];
+        }
         flags.push_back(base::SysNSStringToUTF8(flag));
       }
     }