@@ -255,21 +255,32 @@ namespace tivars
255255 // Here we handle various theta chars. Note thata in TI-ASCII, theta is at 0x5B which is "[" in ASCII.
256256 newName = std::regex_replace (newName, std::regex (" (\u03b8 |\u0398 |\u03F4 |\u1DBF )" ), " [" );
257257
258- // TODO: handle names according to _type
259- newName = std::regex_replace (newName, std::regex (" [^[a-zA-Z0-9]" ), " " );
260- if (newName.length () > sizeof (varname) || newName.empty () || is_numeric (newName.substr (0 , 1 )))
261- {
262- throw std::invalid_argument (" Invalid name given. 8 chars (A-Z, 0-9, θ) max, starting by a letter or θ." );
263- }
264-
265- // TODO: again, properly handle names according to _type... (needs to be implemented by each type)
266- // Quick hack for now...
267258 const auto & typeName = _type.getName ();
259+ const auto & typeId = _type.getId ();
260+
268261 if (typeName == " Real" || typeName == " Complex" || typeName == " Program" || typeName == " ProtectedProgram" )
269262 {
270263 for (auto & c: newName) c = (char ) toupper (c);
271264 }
272265
266+ if (((typeName == " Real" || typeName == " Complex" || (typeId >= 0x1B && typeId <= 0x21 )) && !regex_match (newName, std::regex (R"( ^[[A-Z]$)" ))) // exact types
267+ || ((typeName == " RealList" || typeName == " ComplexList" ) && !regex_match (newName, std::regex (R"( ^\x5D([\x00-\x05])?|([[0-9A-F]{0,5})$)" )))
268+ || ((typeName == " Program" || typeName == " ProtectedProgram" ) && !regex_match (newName, std::regex (R"( ^[[A-Z][[A-Z0-9]{0,7}$)" )))
269+ || (typeName == " Equation" && !regex_match (newName, std::regex (R"( ^\x5E[\x00-\xFF]?$)" )))
270+ || (typeName == " Matrix" && !regex_match (newName, std::regex (R"( ^\x5C[\x00-\x09]?$)" )))
271+ || (typeName == " String" && !regex_match (newName, std::regex (R"( ^\xAA[\x00-\x09]?$)" )))
272+ || (typeName == " Pic" && !regex_match (newName, std::regex (R"( ^\x60[\x00-\x09]?$)" )))
273+ || (typeName == " Image" && !regex_match (newName, std::regex (R"( ^\x3C[\x00-\x09]?$)" )))
274+ || (typeName == " GraphDataBase" && !regex_match (newName, std::regex (R"( ^\x61[\x00-\x09]?$)" ))))
275+ {
276+ newName = " " ;
277+ }
278+
279+ if (newName.length () > sizeof (varname) || newName.empty ())
280+ {
281+ throw std::invalid_argument (" Invalid name given. 8 chars (A-Z, 0-9, θ) max, starting by a letter or θ." );
282+ }
283+
273284 newName = str_pad (newName, sizeof (varname), " \0 " );
274285 std::copy (newName.begin (), newName.end (), varname);
275286 }
0 commit comments