<commit_before>//******************************************************************************************************
//  SignalReference.cs - Gbtc
//
//  Copyright  2012, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
//  not use this file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://www.opensource.org/licenses/MIT
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  05/05/2009 - <NAME>
//       Generated original version of source code
//  12/17/2012 - <NAME>
//       Modified Header.
//
//******************************************************************************************************

using System;

namespace GSF.Units.EE
{
    /// <summary>
    /// Represents a signal that can be referenced by its constituent components.
    /// </summary>
    public struct SignalReference : IEquatable<SignalReference>, IComparable<SignalReference>
    {
        #region [ Members ]

        // Fields

        /// <summary>
        /// Gets or sets the acronym of this <see cref="SignalReference"/>.
        /// </summary>
        public string Acronym;

        /// <summary>
        /// Gets or sets the signal index of this <see cref="SignalReference"/>.
        /// </summary>
        public int Index;

        /// <summary>
        /// Gets or sets the <see cref="SignalKind"/> of this <see cref="SignalReference"/>.
        /// </summary>
        public SignalKind Kind;

        /// <summary>
        /// Gets or sets the cell index, if applicable, of this <see cref="SignalReference"/>.
        /// </summary>
        public int CellIndex;

        #endregion

        #region [ Constructors ]

        /// <summary>
        /// Creates a new <see cref="SignalReference"/>.
        /// </summary>
        /// <param name="signal"><see cref="string"/> representation of this <see cref="SignalReference"/>.</param>
        public SignalReference(string signal)
        {
            // Signal reference may contain multiple dashes, we're interested in the last one
            int splitIndex = signal.LastIndexOf('-');

            // Assign default values to fields
            Index = 0;
            CellIndex = 0;

            if (splitIndex > -1)
            {
                string signalType = signal.Substring(splitIndex + 1).Trim().ToUpper();
                Acronym = signal.Substring(0, splitIndex).Trim().ToUpper();

                // If the length of the signal type acronym is greater than 2, then this
                // is an indexed signal type (e.g., CORDOVA-PA2)
                if (signalType.Length > 2)
                {
                    Kind = signalType.Substring(0, 2).ParseSignalKind();

                    if (Kind != SignalKind.Unknown)
                        Index = int.Parse(signalType.Substring(2));
                }
                else
                    Kind = signalType.ParseSignalKind();
            }
            else
            {
                // This represents an error - best we can do is assume entire string is the acronym
                Acronym = signal.Trim().ToUpper();
                Kind = SignalKind.Unknown;
            }
        }

        #endregion

        #region [ Methods ]

        /// <summary>
        /// Returns a <see cref="string"/> that represents the current <see cref="SignalReference"/>.
        /// </summary>
        /// <returns>A <see cref="string"/> that represents the current <see cref="SignalReference"/>.</returns>
        public override string ToString()
        {
            return ToString(Acronym, Kind, Index);
        }

        /// <summary>
        /// Returns the hash code for this <see cref="SignalReference"/>.<commit_msg>GSF.Core: Updated SignalReference parsing to use int.TryParse for more reliable parsing when signal reference inputs are malformed.<commit_after>//******************************************************************************************************
//  SignalReference.cs - Gbtc
//
//  Copyright  2012, Grid Protection Alliance.  All Rights Reserved.
//
//  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
//  the NOTICE file distributed with this work for additional information regarding copyright ownership.
//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
//  not use this file except in compliance with the License. You may obtain a copy of the License at:
//
//      http://www.opensource.org/licenses/MIT
//
//  Unless agreed to in writing, the subject software distributed under the License is distributed on an
//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
//  License for the specific language governing permissions and limitations.
//
//  Code Modification History:
//  ----------------------------------------------------------------------------------------------------
//  05/05/2009 - <NAME>
//       Generated original version of source code
//  12/17/2012 - <NAME>
//       Modified Header.
//
//******************************************************************************************************

using System;

namespace GSF.Units.EE
{
    /// <summary>
    /// Represents a signal that can be referenced by its constituent components.
    /// </summary>
    public struct SignalReference : IEquatable<SignalReference>, IComparable<SignalReference>
    {
        #region [ Members ]

        // Fields

        /// <summary>
        /// Gets or sets the acronym of this <see cref="SignalReference"/>.
        /// </summary>
        public string Acronym;

        /// <summary>
        /// Gets or sets the signal index of this <see cref="SignalReference"/>.
        /// </summary>
        public int Index;

        /// <summary>
        /// Gets or sets the <see cref="SignalKind"/> of this <see cref="SignalReference"/>.
        /// </summary>
        public SignalKind Kind;

        /// <summary>
        /// Gets or sets the cell index, if applicable, of this <see cref="SignalReference"/>.
        /// </summary>
        public int CellIndex;

        #endregion

        #region [ Constructors ]

        /// <summary>
        /// Creates a new <see cref="SignalReference"/>.
        /// </summary>
        /// <param name="signal"><see cref="string"/> representation of this <see cref="SignalReference"/>.</param>
        public SignalReference(string signal)
        {
            // Signal reference may contain multiple dashes, we're interested in the last one
            int splitIndex = signal.LastIndexOf('-');

            // Assign default values to fields
            Index = 0;
            CellIndex = 0;

            if (splitIndex > -1)
            {
                string signalType = signal.Substring(splitIndex + 1).Trim().ToUpper();
                Acronym = signal.Substring(0, splitIndex).Trim().ToUpper();

                // If the length of the signal type acronym is greater than 2, then this
                // is an indexed signal type (e.g., CORDOVA-PA2)
                if (signalType.Length > 2)
                {
                    Kind = signalType.Substring(0, 2).ParseSignalKind();

                    if (Kind != SignalKind.Unknown)
                        int.TryParse(signalType.Substring(2), out Index);
                }
                else
                    Kind = signalType.ParseSignalKind();
            }
            else
            {
                // This represents an error - best we can do is assume entire string is the acronym
                Acronym = signal.Trim().ToUpper();
                Kind = SignalKind.Unknown;
            }
        }

        #endregion

        #region [ Methods ]

        /// <summary>
        /// Returns a <see cref="string"/> that represents the current <see cref="SignalReference"/>.
        /// </summary>
        /// <returns>A <see cref="string"/> that represents the current <see cref="SignalReference"/>.</returns>
        public override string ToString()
        {
            return ToString(Acronym, Kind, Index);
        }

        /// <summary>
        /// Returns the hash code for this <see cref="SignalReference"/>.
{'fraction_non_alphanumeric': 0.17221972084646556, 'fraction_numerical': 0.006978838361098604, 'mean_word_length': 1.8441101152368757, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3631044', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2022, 'n_words': 752}