package com.braintreepayments.cardform.view;

import android.text.InputFilter;
import android.text.Spanned;

import androidx.annotation.VisibleForTesting;

class RemoveSlashesFilter implements InputFilter {

    static RemoveSlashesFilter newInstance(int maxStringLength) {
        return newInstance(new StringBuilder(maxStringLength));
    }

    @VisibleForTesting
    static RemoveSlashesFilter newInstance(StringBuilder stringBuilder) {
        return new RemoveSlashesFilter(stringBuilder);
    }

    private StringBuilder stringBuilder;

    private RemoveSlashesFilter(StringBuilder stringBuilder) {
        this.stringBuilder = stringBuilder;
    }

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        // re-use string buffer to prevent unnecessary memory allocations while user is typing
        stringBuilder.setLength(0);

        int numChars = source.length();
        for (int index = 0; index < numChars; index++) {
            char c = source.charAt(index);
            if (source.charAt(index) != '/') {
                stringBuilder.append(c);
            }
        }
        return stringBuilder.toString();
    }
}

@@ -201,16 +201,58 @@
 lter %7B%0A%0A
+    private StringBuilder stringBuilder;%0A%0A
     stat
@@ -543,50 +543,8 @@
  %7D%0A%0A
-    private StringBuilder stringBuilder;%0A%0A
     

Move properties to top of file in RemoveSlashesFilter.