From d10ac403fc150967c271306493fc68cca3b864d6 Mon Sep 17 00:00:00 2001 From: Robert Atkinson Date: Thu, 19 Nov 2015 15:05:26 -0800 Subject: [PATCH] special error message for carriage returns --- .../FtcRobotControllerActivity.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/FtcRobotController/src/main/java/com/qualcomm/ftcrobotcontroller/FtcRobotControllerActivity.java b/FtcRobotController/src/main/java/com/qualcomm/ftcrobotcontroller/FtcRobotControllerActivity.java index 87bed8c783a..0995ec982f2 100644 --- a/FtcRobotController/src/main/java/com/qualcomm/ftcrobotcontroller/FtcRobotControllerActivity.java +++ b/FtcRobotController/src/main/java/com/qualcomm/ftcrobotcontroller/FtcRobotControllerActivity.java @@ -578,6 +578,24 @@ boolean isValidWifiDirectName(String name) { return this.legalWifiDirectNamePattern.matcher(name).matches(); } + boolean containsNewline(String name) + { + return name.contains("\n") || name.contains("\r"); + } + String withoutNewlines(String name) + { + StringBuilder result = new StringBuilder(); + for (int ich = 0; ich < name.length(); ich++) + { + char ch = name.charAt(ich); + switch (ch) + { + case '\r':case '\n': break; + default: result.append(ch); break; + } + } + return result.toString(); + } /** Is this peer a driver station? If in doubt, answer 'no'*/ boolean isDriverStation(WifiP2pDevice peer) @@ -624,7 +642,12 @@ public void wifiDirectUpdate(WifiDirectAssistant.Event event) // Check the robot controller name for legality String robotControllerName = assistant.getDeviceName(); if (!isValidWifiDirectName(robotControllerName)) - reportWifiDirectError("\"%s\" is not a legal robot controller name (see )", robotControllerName); + { + if (containsNewline(robotControllerName)) + reportWifiDirectError("robot controller name \"%s\" contains a carriage return: PLEASE FIX immediately", withoutNewlines(robotControllerName)); + else + reportWifiDirectError("\"%s\" is not a legal robot controller name (see )", robotControllerName); + } // We'd like to check all the peers as well, but some of them may not be actually // the driver station but instead, e.g., development laptops. So we need to be a @@ -634,7 +657,12 @@ public void wifiDirectUpdate(WifiDirectAssistant.Event event) if (isDriverStation(peer)) { if (!isValidWifiDirectName(peer.deviceName)) - reportWifiDirectError("\"%s\" is not a legal driver station name (see )", peer.deviceName); + { + if (containsNewline(peer.deviceName)) + reportWifiDirectError("driver station name \"%s\" contains a carriage return: PLEASE FIX immediately", withoutNewlines(peer.deviceName)); + else + reportWifiDirectError("\"%s\" is not a legal driver station name (see )", peer.deviceName); + } } }