Is Empty#
Strings / Is Empty
Can Read
Cannot Write
Description#
Returns True if the text has no characters at all
Parameters#
| Name | Description |
|---|---|
| Text | The text that is checked |
| Ignore Whitespaces | Whether a text made only of spaces, tabs and new lines counts as empty |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Is Empty")]
[Category("Strings/Is Empty")]
[Description("Returns True if the text has no characters at all")]
[Image(typeof(IconNull), ColorTheme.Type.Yellow, typeof(BadgeString))]
[Parameter("Text", "The text that is checked")]
[Parameter("Ignore Whitespaces", "Whether a text made only of spaces, tabs and new lines counts as empty")]
[Keywords("String", "Null", "None", "Blank", "Whitespace", "Length")]
[Serializable]
public class TypeBoolStringIsEmpty : TypeBool
{
[SerializeField] private GetString m_Text = new GetString();
[SerializeField] private GetBool m_IgnoreWhitespaces = new GetBool(true);
public override bool GetPreview(GameObject source) => IsEmpty(
this.m_Text.GetPreview(source),
this.m_IgnoreWhitespaces.GetPreview(source)
);
public override bool Get(Args args) => IsEmpty(
this.m_Text.Get(args),
this.m_IgnoreWhitespaces.Get(args)
);
private static bool IsEmpty(string text, bool ignoreWhitespaces)
{
return ignoreWhitespaces
? string.IsNullOrWhiteSpace(text)
: string.IsNullOrEmpty(text);
}
public override string ToString()
{
return $"{this.m_Text} is Empty";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}