Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/Appearances.cpp (C++)

Code before:

                    uint32_t length;
                    if (SUCCEEDED(names->GetStringLength(localeIndex, &length)))
                    {
                        // it is reasonable to assume that the name length is not going to exceed 512 chars
                        wchar_t name[512];
                        if (SUCCEEDED(names->GetString(localeIndex, name, length + 1)))
                        {
                            fontAxesTagsAndNames.Insert(tagString, winrt::hstring{ name });
                            continue;
                        }
                    }
                    // if there was no name found, it means the font does not actually support this axis
                    // don't insert anything into the vector in this case
                }
            }
        }
        return fontAxesTagsAndNames;
    }

    winrt::hstring Font::_axisTagToString(DWRITE_FONT_AXIS_TAG tag)
    {
        std::wstring result;
        for (int i = 0; i < 4; ++i)
        {
            result.push_back((tag >> (i * 8)) & 0xFF);
        }
        return winrt::hstring{ result };
    }

    AxisKeyValuePair::AxisKeyValuePair(winrt::hstring axisKey, float axisValue, const Windows::Foundation::Collections::IMap<winrt::hstring, float>& baseMap, const Windows::Foundation::Collections::IMap<winrt::hstring, winrt::hstring>& tagToNameMap) :
        _AxisKey{ axisKey },
        _AxisValue{ axisValue },
        _baseMap{ baseMap },
        _tagToNameMap{ tagToNameMap }
    {
        if (_tagToNameMap.HasKey(_AxisKey))
        {
            int32_t i{ 0 };
            // this loop assumes that every time we iterate through the map
            // we get the same ordering
            for (const auto tagAndName : _tagToNameMap)
            {
                if (tagAndName.Key() == _AxisKey)
                {
                    _AxisIndex = i;
                    break;
                }
                ++i;
            }
        }

Review comment (suggestion):
note to self:
> ```DWRITE_MAKE_FONT_AXIS_TAG('c', 's', 't', 'm');```

so this is literally iterating over each of the `char`s embedded in the value of the `DWRITE_FONT_AXIS_TAG` and then sticking them into a string

Code after:
                        UINT32 length = 0;
                        if (SUCCEEDED(names->GetStringLength(localeIndex, &length)))
                        {
                            winrt::impl::hstring_builder builder{ length };
                            if (SUCCEEDED(names->GetString(localeIndex, builder.data(), length + 1)))
                            {
                                fontAxesTagsAndNames.insert(std::pair<winrt::hstring, winrt::hstring>(_axisTagToString(axesVector[i].axisTag), builder.to_hstring()));
                                continue;
                            }
                        }
                        // if there was no name found, it means the font does not actually support this axis
                        // don't insert anything into the vector in this case
                    }
                    _fontAxesTagsAndNames = winrt::single_threaded_map(std::move(fontAxesTagsAndNames));
                }
            }
        }
        return _fontAxesTagsAndNames;
    }

    winrt::hstring Font::_axisTagToString(DWRITE_FONT_AXIS_TAG tag)
    {
        std::wstring result;
        for (int i = 0; i < 4; ++i)
        {
            result.push_back((tag >> (i * 8)) & 0xFF);
        }
        return winrt::hstring{ result };
    }

    AxisKeyValuePair::AxisKeyValuePair(winrt::hstring axisKey, float axisValue, const Windows::Foundation::Collections::IMap<winrt::hstring, float>& baseMap, const Windows::Foundation::Collections::IMap<winrt::hstring, winrt::hstring>& tagToNameMap) :
        _AxisKey{ axisKey },
        _AxisValue{ axisValue },
        _baseMap{ baseMap },
        _tagToNameMap{ tagToNameMap }
    {
        if (_tagToNameMap.HasKey(_AxisKey))
        {
            int32_t i{ 0 };
            // IMap guarantees that the iteration order is the same every time
            // so this conversion of key to index is safe
            for (const auto tagAndName : _tagToNameMap)
            {
                if (tagAndName.Key() == _AxisKey)
                {
                    _AxisIndex = i;
                    break;
                }
                ++i;
            }
        }