MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ConvertKey

Method ConvertKey

source/script_object.cpp:2364–2398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2362}
2363
2364void Map::ConvertKey(ExprTokenType &key_token, LPTSTR buf, SymbolType &key_type, Key &key)
2365// Converts key_token to the appropriate key_type and key.
2366// The exact type of the key is not preserved, since that often produces confusing behaviour;
2367// for example, guis[WinExist()] := x ... x := guis[A_Gui] would fail because A_Gui returns a
2368// string. Strings are converted to integers only where conversion back to string produces
2369// the same string, so for instance, "01" and " 1 " and "+0x8000" are left as strings.
2370{
2371 SymbolType inner_type = key_token.symbol;
2372 if (inner_type == SYM_VAR)
2373 {
2374 switch (key_token.var->IsPureNumericOrObject())
2375 {
2376 case VAR_ATTRIB_IS_INT64: inner_type = SYM_INTEGER; break;
2377 case VAR_ATTRIB_IS_OBJECT: inner_type = SYM_OBJECT; break;
2378 case VAR_ATTRIB_IS_DOUBLE: inner_type = SYM_FLOAT; break;
2379 default: inner_type = SYM_STRING; break;
2380 }
2381 }
2382 if (inner_type == SYM_OBJECT)
2383 {
2384 key_type = SYM_OBJECT;
2385 // Set i to support the way FindItem() is used. Otherwise on 32-bit builds the
2386 // upper 32 bits would be potentially uninitialized, and searches could fail.
2387 key.i = (IntKeyType)(INT_PTR)TokenToObject(key_token);
2388 return;
2389 }
2390 if (inner_type == SYM_INTEGER)
2391 {
2392 key.i = TokenToInt64(key_token);
2393 key_type = SYM_INTEGER;
2394 return;
2395 }
2396 key_type = SYM_STRING;
2397 key.s = TokenToString(key_token, buf);
2398}
2399
2400Map::Pair *Map::FindItem(ExprTokenType &key_token, LPTSTR aBuf, SymbolType &key_type, Key &key, index_t &insert_pos)
2401// Searches for an item with the given key, where the key is a token passed from script.

Callers

nothing calls this directly

Calls 4

TokenToObjectFunction · 0.85
TokenToInt64Function · 0.85
TokenToStringFunction · 0.85
IsPureNumericOrObjectMethod · 0.80

Tested by

no test coverage detected